谷歌地图(标记)

时间:2014-04-02 06:45:58

标签: javascript google-maps

google.maps.event.addDomListener(window, 'load', init);

function init() {

var myOptions = {
    zoom: 12,
    center: new google.maps.LatLng(35.900169, 14.511906),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    styles: [{"stylers": [{"saturation": -100},{"gamma": 0.8}, {"lightness": 4},{"visibility": "on"}]},{"featureType": "landscape.natural","stylers": [{"visibility": "on"},{"color": "#5dff00"},{"gamma": 4.97},{"lightness": -5},{"saturation": 100}]}]     
};

var map = new google.maps.Map(document.getElementById('contactusmap'), myOptions);
var markerNew = new google.maps.MarkerImage(
  'images/googlepin.png',
  new google.maps.Size(32,37)
);
var marker = new google.maps.Marker({
  position: google.maps.LatLng(35.900169, 14.511906),
  map: map,
  icon: markerNew,
  title:"You found us! :)"
});
marker.setMap(map);
}

标记似乎没有出现但没有错误..有关我应该做什么的任何想法都会出现? :■

2 个答案:

答案 0 :(得分:0)

var marker = new google.maps.Marker({
  position: google.maps.LatLng(35.900169, 14.511906),
  map: map,
  icon: markerNew,
  title:"You found us! :)"
});

在上面的代码中,

缺少实例化google.maps.LatLng

 position:   google.maps.LatLng(35.900169, 14.511906), 
           |
           |_____ Add the new Keyword

将其修复为

position: new google.maps.LatLng(35.900169, 14.511906), 

JSFiddle

答案 1 :(得分:0)

如果你评论

,我试过你的代码工作正常
styles: [{"stylers": [{"saturation": -100},{"gamma": 0.8}, {"lightness": 4},{"visibility": "on"}]},{"featureType": "landscape.natural","stylers": [{"visibility": "on"},{"color": "#5dff00"},{"gamma": 4.97},{"lightness": -5},{"saturation": 100}]}]

并在

中添加“new”关键字
 position: new google.maps.LatLng(35.900169, 14.511906),

请检查..希望对你有用....