0

实现这一目标的最佳方法是什么?提炼,我想,当用户注册我的网站时,要求他们通过标记在谷歌地图上选择他们的位置,他们可以将其拖放到他们想要的位置。这个谷歌地图是表单的一部分,在提交时,我想获取该数据的位置,对其进行清理,然后将其插入我的数据库中。

我只是坚持如何将标记的位置放入我的 PHP 表单中进行处理。

我以前知道如何使用 AJAX 从数据库中请求信息,以服务器端 PHP 表单处理它,然后通过 AJAX 将其发送给我的谷歌地图脚本以获取和显示。我只是想知道我将如何在本质上相反的方向(客户端->服务器而不是服务器->客户端)实现这一点。

有任何想法吗?

4

1 回答 1

1

The "old school" solution for this was a clickable image as a form element.

  <input name="coord" type="image" src="map.png">

That gives you two parameters coord.x and coord.y measured in pixels. And it worked even back in the days before javascript, for example in the Xerox PARC Map Viewer.

A Javascript solution would be: When either the map is clicked or the Marker is moved, copy the location to two (possibly hidden) fields long + lat in your form.

I'd recommend using leaflet, not google maps. Here's an example with leaflet:

http://leafletjs.com/examples/quick-start.html#dealing-with-events

于 2013-08-29T09:22:18.263 回答