Drawing anonymous circles in Google Maps
Asked Answered
O

1

1

I'm trying to draw a google maps that has multiple Circle overlays, however I do not want to reveal the correct center of the radius.

So for example, myLatlng is my lat/lon center of the radius, I want to draw a circle not around it, but a circle that will include that point.

This is how I currently draw my circle:

        var myLatlng = new google.maps.LatLng(33.33333,22.22222);
        var circle = new google.maps.Circle({
              map: map,
              radius: 3218,
              strokeColor: "#FFAA00",
              fillColor: "#00AAFF",
              fillOpacity: 0.3,
              center: myLatlng,
              zIndex: 99999,

        });

33.33333,22.22222 is a 'secret' location that I do not want to reveal, however I would like to have that point within the circle.

Is that possible?

Thanks!

Ostracon answered 28/3, 2011 at 13:59 Comment(5)
Could you just add some random small values to lat/long?Garlandgarlanda
@Jeff Foster - can you elaborate? I don't get it..Ostracon
He's saying add a random decimal value to the lat/long position, an amount less than the radius of the circle, to offset its position from true.Eu
@D.N, @Jeff Foster - what do you mean a 'random' decimal value? That decimal value needs to be within the radius, how can I make sure of that? Am I missing your point?Ostracon
If you move the center of the circle to some other arbitrary location, but the distance between the true center and your new center is less than the radius of the circle you are drawing (or inner-most radius if drawing a thicker circle), then it will naturally contain your true point.Eu
G
1

In your example code. The circle could move anywhere such that 33.3 and 22.2 could still be included.

One way to do this would be to simply add a random offset.

    // Generate random between -5 and 5 (just an example)
    var latOffset = Math.floor(Math.random()*11) - 5;
    var longOffset = Math.floor(Math.random()*11) - 5;
    var myLatlng = new google.maps.LatLng(33.33333 + latOffset,22.22222 + longOffset);

The tricky bit you've got is to ensure that the random offset doesn't move the circle out of bounds. The section Expressing latitude and longitude as linear units on Wikipedia should help.

Garlandgarlanda answered 28/3, 2011 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.