javascript - Why is the geolocation not working when I loop through locations -
javascript - Why is the geolocation not working when I loop through locations -
i have various locations utilize establishing persons location want utilize geolocation if available, number 1 element (2nd) of locations array. if utilize code not homecoming position (new google.map.latlng) @ all. know if there wrong code or problem be.
for (var = 0; < locations.length; i++) { var newlat = parsefloat(locations[i][1]) + (math.random() -.5) / 1500; var newlng = parsefloat(locations[i][2]) + (math.random() -.5) / 1500; if(i == 1){ if (navigator.geolocation) { navigator.geolocation.getcurrentposition(function (position) { var mylatlng = new google.maps.latlng(position.coords.latitude, position.coords.longitude); }); } else { var mylatlng = new google.maps.latlng(newlat, newlng); } } else { var mylatlng = new google.maps.latlng(newlat, newlng); }
}
thx comments. fixed getting current location outside loop , checking value within loop.
javascript google-maps-api-3 geolocation
Comments
Post a Comment