douhuanqiao5290 2013-08-29 09: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 09: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

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

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False