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

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

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用