을 변경 속성이 ,Google지도 API for 루프에서 마커와 여기 <p></p>지도는 함수의 인수입니다 (아약스 succes에 함수의 코드
success: function(data) {
var tmpmap = map; //Without this the map wont let me add markers
ris = JSON.parse(data); //Parsing to json
for (var i = 0; i < ris.length - 1; i++) {//Here is the for
var id = ris[i].id_sede; //Here i get the id from the json
var marker = new google.maps.Marker({ //Here i create the marker
map: tmpmap,
mid: id, //And there is where i got that problem.
position: {
lat: parseFloat(ris[i].latitude),
lng: parseFloat(ris[i].longitude)
}
});
아약스 위도를 포함하는 일반 SQL 쿼리가 수집 한 데이터를 ID와 몇 가지 추가 정보를 경도 :)이 코드가 포함되어 있습니다.
그래서 문제는 다음과 같습니다. for의 모든주기에서 이전에 생성 된 각 표식은 현재 '중간'(지도 ID)의 값으로 간주됩니다.
TL; DR 저는 모든 마커 대신 1 2 3 4
그리고 중간의 값으로 4 것이다 사이클의 끝에서와 같은 중앙 1 2 3 4 있었다 4 개 마커를 갖고 마지막 질문은 : 어떻게이 행동을 막을 수 있습니까? 마커를 올바르게 만드나요? 그리고 왜 내가 마커의 가치를 바꿀 때 다른 모든 마커도 똑같이합니까?
success: function (data) {
var tmpmap = map; //Without this the map wont let me add markers
ris = JSON.parse(data); //Parsing to json
for (var i = 0; i < ris.length - 1; i++) { //Here is the for
// IIFE
(function (entry) {
// remember original element as variable entry
var marker = new google.maps.Marker({ //Here i create the marker
map: tmpmap,
mid: entry.id_sede, // still the original ID
position: {
lat: parseFloat(entry.latitude),
lng: parseFloat(entry.longitude)
}
});
}) (ris[i]); // pass original element into IIFEE
}
});
를 첫 번째 마커 변수 i
이미 가지고있는 상태 ris.length - 1
에 도달 할 수의 'ID 때까지 때문에 인생 않고 각 메이커가 자신의 데이터입니다 얻을 수 있도록
많은 도움을 주셔서 감사합니다. –
당신은 환영합니다 :) – Blauharley
그것이 모든 문제를 해결하는 데 도움이된다면, 답을 올바른 답으로 표시하십시오, 감사합니다. – Blauharley