[英]Google Maps - Extract coordinates of the map's center?
I'm hoping to use a Google Map in this way: User zooms in on the location they want (using either pan & zoom or a search bar above the map) and the coordinates of the center of the map are passed down to my PHP script as either "$lat" & "$lon" OR "$coords". 我希望以这种方式使用Google地图:用户放大所需的位置(使用平移和缩放或地图上方的搜索栏),并将地图中心的坐标传递到我的PHP脚本为“ $ lat”和“ $ lon”或“ $ coords”。 If someone could find or write some code that does this I'd be elated... Let me know if more info is needed... My understanding of JavaScript (and even PHP) is limited so please try to be as complete as you can :)
如果有人可以找到或编写一些实现此目的的代码,我会很高兴...如果需要更多信息,请告诉我...我对JavaScript(甚至PHP)的理解是有限的,因此请尝试与您一样完整能够 :)
So, this is going to be problematic (and virtually impossible) because the PHP code is executed server side, before the page finishes loading in the client's browser. 因此,这将是有问题的(几乎是不可能的),因为在页面完成在客户端浏览器中的加载之前,PHP代码是在服务器端执行的。 Javascript is executed "live" as the user does things in the browser, so there really isn't an easy straightforward way to push from JS to PHP.
当用户在浏览器中执行操作时,JavaScript是“实时”执行的,因此,实际上没有简单易行的方法将JS推送到PHP。
To properly answer the question we need to know what you want to do with the coordinate data, and where this is the whole "framework" in your app, ex: 为了正确回答这个问题,我们需要知道您想对坐标数据做什么,以及这是应用程序中整个“框架”的位置,例如:
You have a few options (ordered simplest to hardest) 您有几种选择(从最简单到最困难的顺序排列)
Since you asked, you can get the map's center location by doing map.getCenter()
, which returns a lat/lon pair 如您
map.getCenter()
,您可以通过执行map.getCenter()
来获取地图的中心位置,该方法会返回map.getCenter()
对
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.