Google 地图 - 用户精确定位位置
是否可以允许我的网站用户在我使用 Google Maps API 显示的地图上标记地点?然后我需要将该位置坐标保存到数据库中。
我一直在浏览谷歌地图 API,我发现我可以使用网络服务进行如下搜索:
http://maps.google.com/maps/geo?q=Maine,+United+States&output=json&oe=utf8\&sensor=false&key=my_key
但我不确定它是否在门牌号级别上工作(我需要它),而且我不知道确定如何显示“您是说吗?”当用户拼写错误地址时向用户发送信息。
有人有想法吗?
谢谢,
Is it possible to allow users of my website to mark places on a map I display using Google Maps API? I need to then save that location coordinates to a db.
I've been looking through the google maps API, I found that I can use the web service to do searches like this:
http://maps.google.com/maps/geo?q=Maine,+United+States&output=json&oe=utf8\&sensor=false&key=my_key
But I am not sure it's working on a house number level (which I need it to) and I'm not sure how to display a 'did you mean?' to the user when he misspells the address..
Anyone have an idea?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个很好的例子
http://digitalinspiration.com/community/location.html
使用这样的代码:
应该是您正在寻找的。
There is nice example of what you want
http://digitalinspiration.com/community/location.html
Using code like this:
Should be what you're looking for.
我已经构建了一个使用 Maps API 来显示全球赛事(300 多项体育赛事)的网站,所以是的,这是可能的。一般来说,地理编码效果非常好(就像在地图网站上一样)。我将其与地图显示一起使用,用户可以拖动标记来调整确切位置,然后保存坐标。这样,您就不再需要“您的意思是吗?”类型的框。
I've built a site which uses Maps API for displaying events across the globe (300+ of sport events), so yes, it's possible. The geocoding works really well in general (just as on the Maps site). I've used it with a Map display where the user can drag a marker to adjust the exact location, then saved the coordinates. In this way, you won't really need a 'did you mean?'-type box.
我最近编写并开源了一个 Google 地理编码 API 的 SDK这应该会让 API 的使用变得更容易一些。
请注意,这是针对 v3 API 的,而在上面的代码中,您引用的是 v2 API(现已弃用)
API 本身会自动更正以下拼写错误输入。因此,如果您想确保用户输入的位置实际上是街道地址,您可以像这样(使用我的 SDK)执行此操作。
如果他们的拼写错误非常严重,以至于 API 找不到任何内容,那么
$response->hasResults()
将返回false
(或者,count( $response )
将为0
)I recently wrote and open-sourced an SDK for Google's Geocoding API which should making working with the API a bit easier.
Note that this is for the v3 API, whereas in the code above you're referencing the v2 API (which is now deprecated)
The API itself will auto-correct typos in the input. So if you wanted to make sure that the user entered a location that was actually a street address, you'd do that like so (with my SDK)
If their typo was so egregious that the API didn't find anything, than
$response->hasResults()
would returnfalse
(or,count( $response )
would be0
)