1

Since yesterday I'm trying to add marker in Google Maps Api v3 . I read the documentation and all. Here's my code :

<script type="text/javascript">
  var map;
  function initialize() {

    var mapOptions = {

      center: new google.maps.LatLng(28.63, 77.21),
      zoom: 8,
  disableDefaultUI: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      map = new google.maps.Map(document.getElementById("map-canvas"),
        mapOptions);


  }
 // google.maps.event.addDomListener(window, 'load', initialize);

  function getFillingDetails(){
    var vehicleId = $('#selectVehicle option:selected').val();
    $.getJSON('getFillingDetails.php', {id : vehicleId}, function(data){
  var lat = [];
  var lon = [];
  var price = [];
  $.each(data, function(key, value){
    lat.push(value.latitude);
    lon.push(value.longitude);
    price.push(value.price);
    });
  });

  var myLatlng = new google.maps.LatLng(23.72,77.10);

var marker = new google.maps.Marker({
            position: new google.maps.LatLng(23.72, 72.100),
            map: map,
        });

  }
</script>

Everything looks fine to me. The initialize() function is called after onload of body tag. And getFillingDetails() function is called when I click a button. But still I'm getting no success.

4

2 回答 2

3

您在以下位置有语法错误:

var marker = new google.maps.Marker({
    position: new google.maps.LatLng(23.72, 72.100),
    map: map, <--- get rid of this comma
});

下次您应该在开发人员控制台中查看是否有任何错误。

于 2013-07-16T04:10:32.257 回答
1
// To add the marker to the map, call setMap();
marker.setMap(map);

source : https://developers.google.com/maps/documentation/javascript/markers

于 2013-11-21T10:04:51.733 回答