0
アドレスからのみ複数のマーカーを定義する場合に問題が発生しました。これらのアドレスには座標がありませんので、座標を見つけてマーカーを設定する必要があります。問題は、一部の場所で座標が正しく取得されていないことです。いくつかは別の場所の座標を取得します。GoogleMaps API V3で複数のマーカーを定義する方法
私は "ニューヨーク"、 "ロンドン"、 "パリ"、 "ベルリン"など、さまざまな場所にいるとします。 「ニューヨーク」のマーカーを作成すると、シカゴの緯度と経度が割り当てられているため、緯度と経度以外はすべて正しいです。
はJavaScript:
self.setMarks = function(lista, m){
var marcadores = [];
//We've got several maps, so first we define the map that
//belongs the marker first. This works
var mapa = null;
switch(m){
case 0: //Peninsula
mapa = map;
break;
case 1: //Canarias;
mapa = map3;
break;
case 2: //Baleares
mapa = map2;
break;
}
//We've got an array called lista with the marker information
for (var i = 0; i < lista.length; i++){
var address = lista[i].nombreProvincia + ", Spain";
servicios.getLocation(address).then(function(response){
//The problem starts here
let latitud = response.data.results[0].geometry.location.lat;
let longitud = response.data.results[0].geometry.location.lng;
let mark = new google.maps.Marker({
position: new google.maps.LatLng(latitud, longitud),
id: lista[0].idProvincia,
label: lista[0].total,
title: lista[0].nombreProvincia + "\n" + lista[0].total,
map: mapa
});
//The problem finish here
//We add a listener to each marker, this works fine
mark.addListener("click", function(){
switch(m){
case 0:
self.getPeninsulaProperties(mark.id);
break;
case 1:
self.getMarksFromCanarias(mark.id);
break;
case 2:
self.getMarksFromBaleares(mark.id);
break;
}
});
marcadores.push(mark);
lista.splice(0, 1);
});
//console.log("Fin dirección!!!");
};
}
self.getLocation = function(address){
var promise = $q.defer();
$http.get("http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false")
.then(function(mapData) {
promise.resolve(mapData);
},function(error){
console.log("Error al obtener latitud y longitud: " + error);
});
return promise.promise;
};
私がいない正しく場所から座標を取得するために間違って何をしているのですか?
上のマーカーを定義する方法については、この2つのチュートリアルに従ってみてくださいありがとうございますが、以前に彼らが持っているので、両方のチュートリアルは、私を助けていません各場所の緯度と経度と私の問題は、値を渡さずに各場所の緯度と経度を正しく取得することです。 –