Bookmarks in google maps searching database

Asked

Viewed 193 times

0

How to fill state markers in google maps, searching the latitude, longitude and title data of a database.

Today I already have this function working, but the state data are 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);
  • Do you already have a database with this information? In what format?

  • Actually I don’t have the table yet. It will be a very simple thing, with latitude, longitude and title. The format was thinking of json or xml.

1 answer

0

Hello,

It then makes the result of this database to be written in Json format, with php or the language you prefer. The data is in an array, which you then access with a loop. Check out this documentation:

https://developers.google.com/maps/documentation/javascript/examples/icon-complex

  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]
      });
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.