I’m using a jquery map script called GMap2. I’m calling my php script via jquery/ajax and returning the marker information in json format. The problem is that when I do this, the map points do not show up. But if I manually add the json values, the map points work just fine. Here is my code that calls the gmap code:
$('.shownearby').click(function () {
$.ajax({
cache:false,
url:'path/to/php/script',
dataType:'json',
success: function(data) {
$('#showmap').gMap(
{
latitude : data.dlat,
longitude : data.dlon,
address : data.daddress,
maptype : 'ROADMAP',
zoom : 10,
markers : data.nearby
}
);
}
});
return false;
});
As you see the markers option is loading the value of nearby from the json variable data being passed back on success. You can see an example of an entry that is returned from data.nearby below (I replaced the lat/long/html with dummy data for example purposes):
[{"latitude":"latva","longitude":"latlon","html":"htmlstuff"}]
But again when I pass this information it does not work, however if I paste the json value above that has the lat/long and html values next to markers variable directly the map point comes up just fine. Any idea what the problem is?
Here is example code of using multiple points in the gmap2 script:
$('#map_addresses').gMap({
address: "Quito, Ecuador",
zoom: 5,
markers:[
{
latitude: -2.2014,
longitude: -80.9763,
html: "_latlng"
},
{
address: "Guayaquil, Ecuador",
html: "My Hometown"
},
{
address: "Galapagos, Ecuador",
html: "_address"
}
]
});
Ok looks like it works now. Had to update the markers nearby value to this:
If anyone can verify that is the correct thing to do.