douhuanqiao5290 2013-08-29 01:14
浏览 32
已采纳

如何将来自Javascript的Google Maps标记输入集成到PHP中?

What would be the best way to achieve this? Distilled, I want, when a user signs up to my website, to ask them to select on a Google map their location via a marker, which they can drag and drop to their desired position. This Google Map is part of a form, and on submit, I'd like to take the location of that data, sanitize it, and insert it into my database.

I'm just stuck on how to get the location of the marker into my PHP form for processing.

I have previous knowledge of how to use AJAX to request information from a database, process it in a serverside PHP form, and then send it via AJAX for my Google Maps script to pick up and display. I'm just curious to know how I would implement this in what is essentially the opposite direction (client -> server instead of server -> client).

Any ideas?

  • 写回答

1条回答 默认 最新

  • dongqiaolong9034 2013-08-29 01:22
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥50 大二的web前段开发静态网页纸质版
  • ¥15 robocopy文件复制
  • ¥15 unity安卓打包出现问题
  • ¥15 爱快路由器端口更改错误导致无法访问
  • ¥20 安装catkin时遇到了如下问题请问该如何解决呢
  • ¥15 VAE模型如何输出结果
  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
  • ¥15 fluent设置了自动保存后,会有几个时间点不保存
  • ¥20 激光照射到四象线探测器,通过液晶屏显示X、Y值
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部