[英]Add a marker to an embedded google map?
I'm having a hard time adding a marker to my map. 我很难在地图上添加标记。 I used to use the map engine and embed my maps but this option has become somewhat limited in the new maps.
我曾经使用地图引擎并嵌入地图,但是此选项在新地图中已变得有些局限。 I managed to embed a map with the new design using this function, however I haven't been able to manage to add a red marker to it.
我设法使用此功能将地图嵌入了新设计,但是我无法为其添加红色标记。 This is my code:
这是我的代码:
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(-34.443809, -58.866677),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(map_canvas, map_options);
}
google.maps.event.addDomListener(window, 'load', initialize);
I think to add a marker I must do something like this: 我认为要添加标记,我必须执行以下操作:
var i=new google.maps.Marker({
position:new google.maps.LatLng(-34.443809,-58.866677),
map:map_canvas
})
But I can't figure out how to do it from the documentation. 但是我无法从文档中弄清楚该如何做。 How can I add a marker to the middle of my map?
如何在地图中间添加标记?
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(-34.443809, -58.866677),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(map_canvas, map_options);
var i=new google.maps.Marker({
position:new google.maps.LatLng(-34.443809,-58.866677),
map:map // <------------------ needs to be a google.maps.Map object
})
}
google.maps.event.addDomListener(window, 'load', initialize);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.