Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps marker not showing up API v3

The marker isnt showing up, i read the docs but i cant find the problem, can somebody help me plz?

heres the js:

function initialize() {
      var mapOptions = {
        center: new google.maps.LatLng(-8.064903, -34.896872),
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

      var marker = new google.maps.Marker({
          position: location,
          title:"Hello World!",
          visible: true
      });
      marker.setMap(map);
    }
like image 492
Ramon Vasconcelos Avatar asked Feb 22 '13 14:02

Ramon Vasconcelos


1 Answers

My guess is that your location object is not defined. Try setting your marker position to the same LatLng as your map center and see if it works:

function initialize() {
  latLng = new google.maps.LatLng(-8.064903, -34.896872)
  var mapOptions = {
    center: latLng,
    zoom: 16,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

  var marker = new google.maps.Marker({
      position: latLng,
      title:"Hello World!",
      visible: true
  });
  marker.setMap(map);
}
like image 111
alestanis Avatar answered Sep 20 '22 11:09

alestanis