0

I'm using a method to generate a random locations around my location with given the initial position(lat,long) and radius this method is used From the reference post here, but unfortunately the random locations not generated and display on Google Maps. In my code I had passed the value of lat and long of initial position and given radius around 100 meter around. The code as shown below. It seems I've missed some point in the code.

The code in PHP

            var lat=40.744656;
            var long=-74.005966;
            var southWest = new google.maps.LatLng(lat,long );
                    var r = 100/111300 // = 100 meters
                    , y0 = lat
                    , x0 = long
                    , u = Math.random()
                    , v = Math.random()
                    , w = r * Math.sqrt(u)
                    , t = 2 * Math.PI * v
                    , x = w * Math.cos(t)
                    , y1 = w * Math.sin(t)
                    , x1 = x / Math.cos(y0)
                    newY = y0 + y1
                    newX = x0 + x1
            // set multiple marker
            for (var i = 0; i < 20; i++) {
                // init markers
                var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(newY, newX ),
                    map: map,
                    title: 'Click Me ' + i
                });
  • Please Edit the question to contain sufficient details to be answered without following the link. – Vince Jun 7 at 10:54
  • sure sir, the link is reference to another post thats why i mention it. thx u – john Jun 7 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.