Google Maps API V3 - StreetView más cercano
-
25-09-2019 - |
Pregunta
Cuando StreetView no está disponible para una determinada ubicación, me gustaría encontrar la ubicación posible más cercana con StreetView?
La única forma en que se me ocurre es.
radius = 0;
noOfPoints = 3;
while(radius < 10 miles){
radius = radius + 0.2 miles
points = calculate 4 * noOfPoints at this radius
loop(points)
{
if(streetview visibile for point)
bingo, break;
}
break if bingo;
noOfPOints = noOfPoints+1;
}
Pero esto es ridículamente costoso incluso si quiero encontrar StreetView dentro de un radio de 10 millas y estoy contando con suerte para encontrar StreetView en uno de estos puntos, es decir, podría perder un punto real con StreetView.
¿Alguien puede dirigirme hacia un mejor enfoque?
Solución
Puede intentar utilizar el StreetViewService para ayudarlo a encontrar una vista de calle existente más cercana:
var astorPlace = new google.maps.LatLng(40.729884, -73.990988);
var webService = new google.maps.StreetViewService();
/**Check in a perimeter of 50 meters**/
var checkaround = 50;
/** checkNearestStreetView is a valid callback function **/
webService.getPanoramaByLocation(astorPlace,checkaround ,checkNearestStreetView);
function checkNearestStreetView(panoData){
if(panoData){
if(panoData.location){
if(panoData.location.latLng){
/**Well done you can use a nearest existing street view coordinates**/
}
}
}
/** Else do something... **/
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow