用城市名称设置Google地图标记位置(地址?) [英] Set google maps marker position with city name (address?)

查看:131
本文介绍了用城市名称设置Google地图标记位置(地址?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google Maps JavaScript API V3创建地图



设置标记位置属性时,我们必须将其设置为经度和纬度。



如果我想创建一个国家地图(中心)并在城市名称上放置标记,该怎么办?



我完成了这与静态地图,但我不能找到一种方法来做到这一点与JavaScript地图:



http://maps.googleapis.com/maps/api/staticmap? size = 660x400& sensor = false& centre = malaysia& markers = kualalumpur& markers =巴生& markers = Ipoh



任何想法?

解决方案

您也可以使用 Google Geocoding API 即可执行此操作要求:

  http://maps.googleapis.com/maps/api/geocode/json?address=PLACE&传感器= false 

取决于您想要的回报(Json或XML)以及 PLACE 是您要Geocode的位置,并且每个空间均由 + 替代。我建议你通过添加邮政编码和国家来提供准确的地址以防止出现错误。



使用这个功能的好处是用户没有要在每次显示地图时请求Google Geocoding,尤其是当您有很多标记时。您只有一次地理编码。

Im creating a map with Google Maps JavaScript API V3

When Setting Marker 'Position' Property, We have to set it with latitude and longitude.

what if I want to create a Country map (center) and place markers on Cities with city name?

I have done this with Static maps, but I cant find a way to do this with javascript maps:

http://maps.googleapis.com/maps/api/staticmap?size=660x400&sensor=false&center=malaysia&markers=kualalumpur&markers=Klang&markers=Ipoh

Any Ideas?

解决方案

You can also use the Google Geocoding API to do this, all you have to do is to request :

http://maps.googleapis.com/maps/api/geocode/json?address=PLACE&sensor=false

Depending of what you want in return (Json or XML), and where PLACE is where you want to Geocode, and where every space is replace by +. I advice you to give an accurate address by adding the postal code and the country for exemple to prevent errors.

The advantage of using this is that the user don't have to request the Google Geocoding everytime you show the map, especially when you have a lot of markers. You Geocode once only.

这篇关于用城市名称设置Google地图标记位置(地址?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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