0

I have my map and code to loop through a json array to add marks to a map.

The map loads and I get console output stating that each park has been added to the map but no marker appears on it.

Any ideas?

 function initialize() {
 var mapOptions = {
 center: new google.maps.LatLng(-34.397, 150.644),
 zoom: 2
 };
 var map = new google.maps.Map($('#maptest')[0], mapOptions);
 $.getJSON("/parks.json", function(parks) {
 $.each(parks, function(key, park) {
 if (park.lat && park.lng) {
 var latlng = park.lat + ',' + park.lng;
 var location = new google.maps.LatLng(latlng);
 var marker = new google.maps.Marker({
 position: location,
 map: map
 });
 console.log('Added map marker for ' + park.name + ' at ' + park.lat + ', ' + park.lng);
 }
 });
 });
 }
 google.maps.event.addDomListener(window, 'load', initialize);
asked Nov 27, 2013 at 18:53

1 Answer 1

1

The google.maps.LatLng constructor expects you to pass in the latitude and longitude as number type. Currently, it's being passed in as a string (var latlng = park.lat + ',' + park.lng;). Remove that line and just pass in the park.lat and park.lng values:

var location = new google.maps.LatLng(park.lat, park.lng);

For more reference click here.

answered Nov 27, 2013 at 19:12
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Why I didn't try that I have no idea! Works perfectly now!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.