Javascript 使用 Google Maps API 根据地址动态嵌入地图 - 需要使用 Google 的数据作为标记/气泡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2380613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Google Maps API to dynamically embed a map based on an address - Need to use Google's data for the markers/bubbles
提问by Will M
I am trying to embed a Google Map into a dynamic webpage. The only variable the map depends on is the address of a business. That address comes from the website's database. I cannotjust statically generate embed code for each dynamic page using the same set up. Is there a way I can embed a map based on that address and show a marker/bubble showing Google's information on that business?
我正在尝试将 Google 地图嵌入到动态网页中。地图所依赖的唯一变量是企业的地址。该地址来自网站的数据库。我不能使用相同的设置为每个动态页面静态生成嵌入代码。有没有一种方法可以嵌入基于该地址的地图并显示一个标记/气泡来显示谷歌关于该业务的信息?
So far, I have explored a few options including using the Google Map API and the Google Data API or just messing with the embed code given by Google. If I use the APIs it seems I have to design my own types of markers and maybe even supply my own data.
到目前为止,我已经探索了一些选项,包括使用谷歌地图 API 和谷歌数据 API,或者只是弄乱谷歌提供的嵌入代码。如果我使用 API,似乎我必须设计我自己的标记类型,甚至可能提供我自己的数据。
It doesn't look like there is an easy solution.
看起来没有简单的解决方案。
Any ideas?
有任何想法吗?
Thanks.
谢谢。
EDIT: I'm not hung up on going from an address to a longitude and a latitude. I want the info window or "bubble" for a marker to show Google's information of a business.
编辑:我并没有因为从地址到经度和纬度而挂断电话。我想要一个标记的信息窗口或“气泡”,以显示 Google 的商家信息。
EDIT: On Roy's suggestion I have been trying to use the map and search API together to achieve what I want. However, the only way I can execute a search with searchControl.execute('business name here'); is if the SearchControl is drawn. Thing is though I don't want to show any search controls. I have been able to hide it, but that just seems like an inefficient hack way of solving this.
编辑:根据罗伊的建议,我一直在尝试将地图和搜索 API 一起使用来实现我想要的。但是,我可以使用 searchControl.execute('business name here'); 执行搜索的唯一方法;是如果 SearchControl 被绘制。事情是虽然我不想显示任何搜索控件。我已经能够隐藏它,但这似乎是解决这个问题的低效黑客方法。
回答by Roy
Don't just use the embed code. Write a bit of Javascript that will draw a map for you and pass it the address.
不要只使用嵌入代码。编写一些 Javascript 来为您绘制地图并将地址传递给它。
Loads of examples here: http://code.google.com/apis/maps/documentation/examples/index.html
这里有大量示例:http: //code.google.com/apis/maps/documentation/examples/index.html
I'm not sure which bit you're stuck on, but you don't need to design your own markers. Google can also create a marker from an address and it can find local business information if it has it (using local search API I think).
我不确定您坚持哪一点,但您不需要设计自己的标记。谷歌还可以从地址创建一个标记,如果有的话,它可以找到本地商业信息(我认为使用本地搜索 API)。

