Reputation: 954
So I am trying to use the Google Maps feature with the following codes and the json data. But I get Error: location is undefined error. I dont really understand why because I defined in my codes. I am new to JavaScript, any suggestion to make this code appreciated.
var data = <%=JSON.stringify(Info, null, 2) & vbNewline%>;
function initialize() {
var center = new google.maps.LatLng(48.404840395764175, 2.6845264434814453);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
for (var i = 0; i < 100; i++) {
var location = data[i];
var latLng = new google.maps.LatLng(location.latitude,
location.longitude);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize);
{ "firstname": "", "lastname": "", "location": { "latitude": "48.4048403957642", "longitude": "2.68452644348145" } } { "firstname": "", "lastname": "", "location": { "latitude": "48.4050236871384", "longitude": "2.68512690051361" } } { "firstname": "", "lastname": "", "location": { "latitude": "48.4048403957642", "longitude": "2.68452644348145" } } { "firstname": "", "lastname": "", "location": { "latitude": "48.7570941168018", "longitude": "2.16670989990234" } } { "firstname": "", "lastname": "", "location": { "latitude": "48.404922961092", "longitude": "2.70020564018949" } } { "firstname": "", "lastname": "", "location": { "latitude": "48.8739279353421", "longitude": "2.32875823974609" } } { "firstname": "", "lastname": "", "location": { "latitude": "48.4048403957642", "longitude": "2.68452644348145" } } { "firstname": "", "lastname": "", "location": { "latitude": "41.0349860434783", "longitude": "28.9774059609177" } }
Upvotes: 0
Views: 153
Reputation: 66663
You should probably do
for (var i = 0; i < data.length; i++) {
instead of
for (var i = 0; i < 100; i++) {
Upvotes: 3