javascript geocode latlng variable
-
26-10-2019 - |
Pregunta
Javascript
Estoy seguro de que este es un problema muy simple.
Estoy modificando la línea a continuación y quiero reemplazar (53, 0) con una variable. Sin embargo, la variable que se crea llamada 'resultado', es igual a '(34, 2)', es decir, ya tiene los soportes a su alrededor.
center: new google.maps.LatLng.(53, 0)
Yo he tratado
center: new google.maps.LatLng.(result)
center: new google.maps.LatLng.result
center: new google.maps.LatLng.({result})
¡Y no funciona!
Código completo
var geocoder = new Google.maps.Geocoder ();
if (geocoder) {
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
window.result = results[0].geometry.location;
alert(result);
}
else {
alert('nothing');
}
});
}
function load() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng.(53, 0),
zoom: 10,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
}
Como referencia, alerta (resultado) devuelve
(53.8622017, -2.405405999999971)
Solución
Pruebe nuevo Google.maps.latlng (resultado [0], resultado [1])? Publique dónde se crea la variable 'Resultado'.
Otros consejos
tu poniendo. Después de la latlng, la forma correcta de crear el objeto latlng fue probar de esta manera
center:new google.maps.LatLng(-34.397, 150.644);
aquí . Definir el nivel del paquete y el último latlng fue clase
Al igual que Google es el nivel superior en esos mapas y en ese latlng se definió.
Entonces el latlng tiene 2 parámetros (latitud y longitud)
¿Por qué no configura su centro de mapa en la respuesta?
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
}