dousong3760 2009-05-07 18:57
浏览 43
已采纳

移动谷歌地图标记时触发php功能请求

When a marker is placed, I want to call a php function (in another file) with the latitude and longitude as input and output the result in a div on the page. So whenever the marker is moved, it updates the div with the latest result of the function.

I know I'd need javascript to do this but I'm not very familiar with it and any help would be appreciated.

  • 写回答

2条回答 默认 最新

  • duanlu1876 2009-05-07 21:00
    关注

    Here is an example using jQuery to trigger a HTTP GET when a marker is added to the map and whenever it is dragged. The result of the request is placed in a div with id "outputdiv".

    // create and init map (make sure to have a div element with id "map")
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    
    // this is the marker you want to track
    var marker = new GMarker(new GLatLng(37.4419, -122.1419));
    map.addOverlay(marker);
    
    // create function to be executed on add/end of drag
    var changeCallback = function(latlng) {
      // do HTTP GET to execute PHP function in file, with coordinate
      // as parameter and put result in div with id "outputdiv"
      $("#outputdiv").load("test.php?latlng=" + latlng.toUrlValue());
    };
    
    // add listener triggered whenever drag of marker has ended
    GEvent.addListener(marker, "dragend", changeCallback);
    
    // explicitly call when added
    changeCallback(marker.getLatLng());
    

    Update to answer comment: The latlng parameter of the callback function is a GLatLng object where you may use lat() and lng() to retrieve the individual values. See Google Maps API reference for details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法