开发者

Detect nearest location from Array of Locations by using Google Map APIs

I've an array of locations: {'place1', 'place2', 'place3'} *// these are addresses

Now assume that there is a new location: 'place4'.

I want to detect which one is nearest to 'place4'....comparing from above array of locations....

i.e. tracking nearest location of a point from array of locations...(By using Google Map APIs)..

psuedo code:

foreach(var ite开发者_StackOverflow社区m in array)
{
     var i = TrackNearestLocationByGoogleMapAPIs(item);
     if(i is nerest)
     {
       print(i);  and go out of loop...
     }
}


There is no API-call to do what you want. You have to calculate the distance yourself with the Haversine formula as seen here: http://www.movable-type.co.uk/scripts/latlong.html


I don't think Google Maps API v3 provides a simple mechanism to do this. You might be able to retrieve the latitude and longitude of each location and figure out which point is the closest from that data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜