javascript - How to fetch JSON from a php script -
i able plot list of point on google map using :
(function() { window.onload = function() { var map = new google.maps.map(document.getelementbyid("map"), { center: new google.maps.latlng(41.6, -0.88), zoom: 12, maptypeid: google.maps.maptypeid.roadmap }); // creating json data var json = [ { "nombre": "name1", "lat": "41.653", "long": "-0.907922", }, { "nombre": "name2", "lat": "41.6693", "long": "-0.891317", }, { "nombre": "name3", "lat": "41.6502", "long": "-0.875212", } ]; var infowindow = new google.maps.infowindow(); (var = 0, length = json.length; < length; i++) { var data = json[i], latlng = new google.maps.latlng(data.lat, data.long); // creating marker , putting on map //var iconbase = 'https://dea-srl.net/domenico/traking/js/'; var iconbase = 'https://maps.google.com/mapfiles/kml/shapes/'; var marker = new google.maps.marker({ position: latlng, map: map, title: data.nombre, icon: iconbase + 'schools_maps.png' }); (function(marker, data) { // attaching click event current marker google.maps.event.addlistener(marker, "click", function(e) { infowindow.setcontent(data.nombre); infowindow.open(map, marker); }); })(marker, data); } } })();
it works well, need read location json string format generated this:
{ "locations": [ { "nombre": "name1", "lat": "41.6504", "long": "-0.879137", }, { "nombre": "name2", "lat": "41.6405", "long": "-0.893266", } ] }
this json generated froma php script, thaht available url like: http://myscript.php.
my question is, how can fetch json php script , put javascript variable?
the objects have same structure.
where says json.length
, json[i]
, use yourvariable.locations.length
, yourvariable.locations[i]
, respectively.
Comments
Post a Comment