Next & Nearest Google Streetview for a given IP or Latitude/Longitude [duplicate]
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);
}
};
精彩评论