创建地图后将标记添加到Google Maps v3 [英] Adding Markers to Google Maps v3 After Map Created

查看:110
本文介绍了创建地图后将标记添加到Google Maps v3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Google Maps API方面相对较新。现在我正在开发一个项目,用户可以选择各种搜索过滤器,并在地图上自动显示结果,而无需重新加载页面。到目前为止,我的方法是创建一个带有控件映射的Javascript对象,以便我可以按照我的需要操作它的各个部分(即centerMap(),addMarker(),clearMap()等)。在项目的这个阶段开始之前,我开发了几个概念验证片。

现在我正处于控制GMap的自定义JS对象的位置。 GMap绘制正确,缩放和中心都很好。接下来我尝试运行一个将标记添加到地图的功能。我猜测可能在地图生成后添加标记,我只是在某个地方犯了一个错误。以下是我的代码,因为它存在。我想知道是否有人可以说出为什么我的标记没有显示出来...



任何和所有帮助都非常感谢!



代码: http://pastebin.com/1ZzH9zHk



预先致谢!
Dima

解决方案

在您的代码中,不应该包含

  var map = new google.maps.Map($('map_canvas'),myOptions); 

be

  this.map = new google.maps.Map($('map_canvas'),myOptions); 


I'm relatively new with using Google Maps API. Right now I am working on a project where a user can select various search filters and see results automatically show up on the map without reloading the page. My approach thus far has been to create a Javascript object with controls the map so that I could manipulate pieces of it as I wish (ie, centerMap(), addMarker(), clearMap(), etc). I developed several proof-of-concept pieces before beginning this phase of the project.

Right now I am at the point where I have a custom JS object which controls my GMap. The GMap is drawn correctly, the zoom and center are fine. Next I try to run a function which adds a Marker to the map. I'm guessing it's possible to add markers after a map has been generated and I'm simply making a mistake somewhere. Below is my code as it exists. I'm wondering if anybody can shed some light as to why my marker isn't showing up...

Any and all help is greatly appreciated!

Code: http://pastebin.com/1ZzH9zHk

Thanks in advance!! Dima

解决方案

In your code, shouldn't

var map = new google.maps.Map($('map_canvas'), myOptions);

be

this.map = new google.maps.Map($('map_canvas'), myOptions);

这篇关于创建地图后将标记添加到Google Maps v3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆