谷歌地图不显示API标志 [英] Google maps api marker not showing
本文介绍了谷歌地图不显示API标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能得到的标记,以显示在地图上。谁能帮我找出什么是错的,这将是一个巨大的帮助?
下面是code:
函数初始化(){
变种map_canvas提供=的document.getElementById('map_canvas提供');
VAR myLatlng =新google.maps.LatLng(33.748995,-84.387982);
VAR的MapOptions = {
中心:myLatlng,
变焦:11,
mapTypeId设为:google.maps.MapTypeId.TERRAIN
}
VAR地图=新google.maps.Map(map_canvas提供,的MapOptions);
TestMarker();
}//添加标记到页面功能。
功能addMarker(位置){
标记=新google.maps.Marker({
位置:位置,
地图:地图
});
}//测试addMarker功能
功能TestMarker(){
亚特兰大=新google.maps.LatLng(33.748995,-84.387982);
addMarker(亚特兰大);
}google.maps.event.addDomListener(窗口'负荷',初始化);
解决方案
您似乎缺少了 VAR
关键字在标记<前/ code>和
亚特兰大
变量。要解决,我还要宣布地图
,标记
和亚特兰大
之外的变量初始化全局空间()
功能,所以他们对其他功能进行访问。试试这个:
VAR地图;
VAR标记;
VAR亚特兰大;函数初始化(){
变种map_canvas提供=的document.getElementById('map_canvas提供');
VAR myLatlng =新google.maps.LatLng(33.748995,-84.387982);
VAR的MapOptions = {
中心:myLatlng,
变焦:11,
mapTypeId设为:google.maps.MapTypeId.TERRAIN
};
地图=新google.maps.Map(map_canvas提供,的MapOptions);
TestMarker();
}//添加标记到页面功能。
功能addMarker(位置){
标记=新google.maps.Marker({
位置:位置,
地图:地图
});
}//测试addMarker功能
功能TestMarker(){
亚特兰大=新google.maps.LatLng(33.748995,-84.387982);
addMarker(亚特兰大);
}google.maps.event.addDomListener(窗口'负荷',初始化);
I can not get the marker to show up on the map. Can anyone help me find out what is wrong that would be a huge help?
Here is the code:
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var myLatlng = new google.maps.LatLng(33.748995, -84.387982);
var mapOptions = {
center: myLatlng,
zoom: 11,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
var map = new google.maps.Map(map_canvas, mapOptions);
TestMarker();
}
// Function for adding a marker to the page.
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
map: map
});
}
// Testing the addMarker function
function TestMarker() {
Atlanta = new google.maps.LatLng(33.748995, -84.387982);
addMarker(Atlanta);
}
google.maps.event.addDomListener(window, 'load', initialize);
解决方案
You appear to be missing the var
keyword in front of the marker
and Atlanta
variables. To fix, I would also declare the map
, marker
and Atlanta
variables outside of the initialize()
function in the global space, so they are accessible to other functions. Try this:
var map;
var marker;
var Atlanta;
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var myLatlng = new google.maps.LatLng(33.748995, -84.387982);
var mapOptions = {
center: myLatlng,
zoom: 11,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(map_canvas, mapOptions);
TestMarker();
}
// Function for adding a marker to the page.
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
map: map
});
}
// Testing the addMarker function
function TestMarker() {
Atlanta = new google.maps.LatLng(33.748995, -84.387982);
addMarker(Atlanta);
}
google.maps.event.addDomListener(window, 'load', initialize);
这篇关于谷歌地图不显示API标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文