Bookmarks in google maps searching the database

0

How would you fill in state markers in google maps, fetching latitude, longitude and title data from a database.

Today I already have this function working, but the state data is fixed in a javascript.

Below is the code I have today:

function init_map() {
    var myOptions = {
        zoom: 4,
        center: new google.maps.LatLng(-14.2392976,-53.1805017),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    marker = new google.maps.Marker({
        map: map,
        position: new google.maps.LatLng(-27.276409, -48.844043),
        icon: "img/1444113052_map-marker.png",
        title: "Santa Catarina"
    });
    marker = new google.maps.Marker({
        map: map,
        position: new google.maps.LatLng(-18.5779703,-45.4514505),
        icon: "img/1444113052_map-marker.png",
        title: "Minas Gerais"
    });
}


google.maps.event.addDomListener(window, "load", init_map);
    
asked by anonymous 27.10.2016 / 01:21

1 answer

0

Hello,

Then the result of this bank is written in Json format, with php or whatever language you prefer. The data is in an array, which you then access with a loop. Check out this documentation:

link

  var beaches = [
    ['Bondi Beach', -33.890542, 151.274856, 4],
    ['Coogee Beach', -33.923036, 151.259052, 5],
    ['Cronulla Beach', -34.028249, 151.157507, 3],
    ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
    ['Maroubra Beach', -33.950198, 151.259302, 1]
  ];

for (var i = 0; i < beaches.length; i++) {
      var beach = beaches[i];
      var marker = new google.maps.Marker({
        position: {lat: beach[1], lng: beach[2]},
        map: map,
        title: beach[0],
        zIndex: beach[3]
      });
    }
    
01.11.2016 / 18:55