开发者

Next & Nearest Google Streetview for a given IP or Latitude/Longitude [duplicate]

This question already has an answer here: google maps api v3 - nearest streetview (1 answer) Closed 9 years ago.

I'm using ipinfodb.com for a while to get the Latitude and Longitude from the user IP to view the google streetview. But recently ipinfodb has changed their database, and most the latitude/longitude values are changed, because of which I dont get the streetview.

I'm using "Google Maps Javascript API V3 S开发者_如何学运维ervices" but not sure on how to the next and nearest possible GoogleStreetview. Could you please suggest.

Regards


The API has a getPanoramaByLocation method in StreetViewService Class

Below is an example of how to get a streetview within a given radius around the given latLng position, note that if the radius is less than 50 meters the nearest panorama will be returned

var streetViewService = new google.maps.StreetViewService();
streetViewService.getPanoramaByLocation(latLng, radius, function(data, status)
{
    if (status == google.maps.StreetViewStatus.OK)
    {
        var nearStreetViewLocation = data.location.latLng;              
        //...
    }
});          


radius doesn't guarantee the closest street view point. For example: if the view point is 10m away but you define your radius as 1000 then the closest isn't selected. So if you have several points (some really close, some really far) then I would still use iteration:

var streetViewService = new google.maps.StreetViewService();
var radius = 10;

streetViewService.getPanoramaByLocation(latLng, radius, handler);

function handler(data, status) {
    if (status == google.maps.StreetViewStatus.OK) {
        var nearStreetViewLocation = data.location.latLng;              
        //...
    } else {
        radius += 50;
        streetViewService.getPanoramaByLocation(latLng, radius, handler);
    }
}; 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜