谷歌地图不显示API标志

编程入门 行业动态 更新时间:2024-10-26 02:32:04
本文介绍了谷歌地图不显示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 关键字在标记和亚特兰大变量。要解决,我还要宣布地图,标记和亚特兰大之外的变量初始化全局空间()功能,所以他们对其他功能进行访问。试试这个:

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标志

本文发布于:2023-06-07 22:07:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标志   地图   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!