0
votes

I need to add all the markers in a map of google maps from the url of an api for example http://192.168.99.100:8080/api/v1/location this url show:

[{"nid":"23","title":"Acopio en xalapa","created":"1478207996","modified":"1478207996","body":"Acopio en xalapa","cover":"http:\/\/192.168.99.100:8080\/sites\/default\/files\/styles\/original\/public?itok=GVqc4SZo","category":{"title":"Centro de acopio","detail":""},"address":"Venustiano carranza xalapa, veracruz","lat":"-123.1465","lng":"49.3026"},{"nid":"19","title":"Sucursal 1","created":"1476996732","modified":"1477666258","body":"esta es una sucursal muy bonita","cover":"http:\/\/192.168.99.100:8080\/sites\/default\/files\/styles\/original\/public?itok=GVqc4SZo","category":{"title":"Sucursal","detail":""},"address":"Av tripulacion #34, col. nolose","lat":"-123.146567","lng":"49.302600"}]

I have to show all the markers in the map based on the latitude (lat) and length (lng) of that json generated by that url.

Thanks for you help.

1

1 Answers

1
votes

Seems that your content is an array of objects then assuming that your resulting url is assigned at var named my_var you could accessing this way

 my_var[0].nid  // 23
 my_var[0].title// Acopio en xalapa
 .....
 my_var[0].address // Venustiano carranza xalapa, veracruz
 my_var[0].lat  // -123.1465
 my_var[0].lng  // 49.3026

 my_var[1].nid  // 19
 my_var[1].title// Sucursal 1
 .....
 my_var[1].address // Av tripulacion #34, col. nolose
 my_var[1].lat  // -123.146567
 my_var[1].lng  //49.302600

Assuming you are able to create a map you can populate you map with markers this

var markers = [];

for (i=0; i<my_var.length; i++){
  markers[i] = new google.maps.Marker({
    position: new google.maps.LatLng( my_var[i].lat, my_var[i].lng),
    map: image
  });