我有一个问题,那个标记没有出现。 地图的风格还可以,除了标记......一切都还可以。
这是html和javascript代码......
function initialize() {
var myLatLng = new google.maps.LatLng(45.431536, 4.380121);
var mapOptions = {
zoom: 14
, center: myLatLng
, disableDefaultUI: false
, scrollwheel: true
, navigationControl: true
, mapTypeControl: false
, scaleControl: true
, draggable: true
, mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'roadatlas']
}
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(45.431536, 4.380121)
, animation: google.maps.Animation.BOUNCE
, icon: 'images/location_pin.png'
, title: 'ASL'
});
var styledMapOptions = {
name: 'US Road Atlas'
};
var usRoadMapType = new google.maps.StyledMapType(roadAtlasStyles, styledMapOptions);
map.mapTypes.set('roadatlas', usRoadMapType);
map.setMapTypeId('roadatlas');
}
google.maps.event.addDomListener(window, "load", initialize);});
感谢您的帮助。
答案 0 :(得分:0)
您的标记中缺少map
属性:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(45.431536, 4.380121)
, animation: google.maps.Animation.BOUNCE
, icon: 'https://cdn2.iconfinder.com/data/icons/flat-ui-icons-24-px/24/location-24-128.png'
, title: 'ASL'
, map : map
});
此外,您在此行中有语法错误:
google.maps.event.addDomListener(window, "load", initialize);});
将其重写为:
google.maps.event.addDomListener(window, "load", initialize);
JSFIddle:https://jsfiddle.net/t9pgsv6g/