Adding Markers to Google Maps v3 After Map Created

孤街浪徒 提交于 2019-12-08 08:10:55

问题


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


回答1:


In your code, shouldn't

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

be

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


来源:https://stackoverflow.com/questions/6335620/adding-markers-to-google-maps-v3-after-map-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!