admin管理员组文章数量:1328660
I have a Json array that contains latitude and longitude coordinates. Here's a sample:
"zones":[{"Zip":35824,"Latitude":34.647995,"Longitude":-86.738549},...
I'm attempting to use loop over the array to parse the coordinates and plot them on a google map. Here's my Javascript:
function getLocations() {
$.getJSON("http://localhost:1117/zones/latlng", function (json) {
var location;
$.each(json.zones, function (i, item) {
location = item.Latitude + ',' + item.Longitude, addMarker(location);
});
});
};
function addMarker(location) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(location),
map: map,
icon: redImage
});
markersArray.push(marker);
}
My problem is the markers end up stacked on top of each other plotted in the upper left corner of the map (right in the middle of the ocean). The location where the markers stack appears nowhere in my Json array. What did I do wrong?
I have a Json array that contains latitude and longitude coordinates. Here's a sample:
"zones":[{"Zip":35824,"Latitude":34.647995,"Longitude":-86.738549},...
I'm attempting to use loop over the array to parse the coordinates and plot them on a google map. Here's my Javascript:
function getLocations() {
$.getJSON("http://localhost:1117/zones/latlng", function (json) {
var location;
$.each(json.zones, function (i, item) {
location = item.Latitude + ',' + item.Longitude, addMarker(location);
});
});
};
function addMarker(location) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(location),
map: map,
icon: redImage
});
markersArray.push(marker);
}
My problem is the markers end up stacked on top of each other plotted in the upper left corner of the map (right in the middle of the ocean). The location where the markers stack appears nowhere in my Json array. What did I do wrong?
Share asked Sep 9, 2011 at 20:04 hughesdanhughesdan 2,85114 gold badges61 silver badges83 bronze badges2 Answers
Reset to default 5I think the problem is that new google.maps.LatLng() expects (number,number) as the parameters and you're passing in a string in the format "number,number".
If you change the addMarker() function to have two parameters (e.g. latitude,longitude) that should work:
function getLocations() {
$.getJSON("http://localhost:1117/zones/latlng", function (json) {
var location;
$.each(json.zones, function (i, item) {
addMarker(item.Latitude,item.Longitude);
});
});
}
function addMarker(lat,lng) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
map: map,
icon: redImage
});
markersArray.push(marker);
}
use clustering .make group of markers as cluster.one cluster will present many markers inside.also make bounds.
本文标签:
版权声明:本文标题:javascript - Plotting LatLng coordinates from Json Array on Google Map --- the markers all stack up in the same location - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742220318a2435331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论