众果搜的博客

脚踏大地,仰望星空,致力于财经投资网站导航与在线网络工具的开发与普及

Search(博客搜索)

热文排行

最近发表

最新评论及回复

« 怎样写一篇优秀的论文?使用驱动精灵升级老电脑的驱动程序 »

谷歌地图API标记不显示解决办法

 如果V3版的google Maps API添加的marker,不显示,看看是不是这个原因。另外,如果代码没有任何原因,应该稍后再试,感觉谷歌地图在国内还是受打击对象。google map从V2升级到V3,可把人害惨了,代码全部需要重新,80%左右的。下次,再开发谷歌地图类的应用,一定要弱耦合地图,把功能尽量用外部实现,以免这家伙又升级。另外,希望google升级的时候,能够提供一个升级包,智能工具,解决代码的升级问题。

 
I have tried numerous variations but none display the Marker on the map. Could anyone help, please?
 
</script>
  <script>
  function initialize() {
      var latlng = new google.maps.LatLng(51.51697, -0.14650);
      var myOptions = {
          zoom: 16,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"),
      myOptions);
  }
 
  // To add the marker to the map, use the 'map' property
    var marker = new google.maps.Marker({
    position: new google.maps.LatLng(51.51697, -0.14650),
    map: map,
    title:"HERE"
});
 
// To add the marker to the map, call setMap();
marker.setMap(map);
  </script>
Thanks a million.
 
javascript google-maps google-maps-api-3
 
Answer:
There are two reasons why the marker doesn't show up:
 
The map variable is local inside the initialize function, so you can't reach it from code outside the function.
 
The initialize function is called from the load event, so you try to add the marker to the map before it exists.
 
Add the marker to the map inside the initialize function. There you have access to the variable, and the map is already created when you add the marker.
 
If you need to access the map outside the initialize function, declare the variable map outside the function.
 
因为google map存在初始化的问题,所以定义变量等,要注意位置。如果定义不好,就无法显示。另外,JavaScript是我见过最恶心的语言。
  • quote 1.akbingo
  • 不好意思,想问一下地图测绘面积计算工具怎么不能用了?
  • 2014-6-11 16:56:35 回复该留言

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense

Copyright www.zhongguosou.com. Some Rights Reserved.微信号:MiZhiHeiGeTaXiaoMi