【问题标题】:Runing PHP code on click of Google map marker在 Google 地图标记的点击上运行 PHP 代码
【发布时间】:2017-06-14 09:27:30
【问题描述】:

下面是我的php代码:

   <?php
    session_start();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"http://192.168.1.220/cgi-bin/handle_login.tcl");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
                "user=admin&pw=admin&submit=Login&sid=' '");        
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: x-www-form-urlencoded'));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);

    $response=curl_exec($ch);
    echo "<script type='text/javascript'>alert('$response');</script>"."<br/>";
    echo strpos("$response","sid")."<br/>";
    echo strstr($response, 'sid')."<br/>";
    echo substr($response,90,19)."<br/>";
    //$_SESSION['value'] = $response;
    curl_close ($ch);
?>

当用户点击谷歌地图标记时,我需要执行上述代码并将其内容打印为输出。

上面的代码可以执行吗?

【问题讨论】:

  • 是的,找到标记的点击事件。并进行 ajax 调用并将这些代码放入该 ajax 调用中。
  • @Bhavin..非常感谢..完全忘记了ajax..
  • 尝试获取标记的点击事件,然后对将执行此 curl 代码的 php 页面进行 ajax 调用

标签: javascript php google-maps google-maps-api-3


【解决方案1】:

像这样添加addDomListener到点击事件:

function initMap() {
        var mapDiv = document.getElementById('map');
        var map = new google.maps.Map(mapDiv, {
          zoom: 8,
          center: new google.maps.LatLng(-34.397, 150.644)
        });

        // We add a DOM event here to show an alert if the DIV containing the
        // map is clicked.
        google.maps.event.addDomListener(mapDiv, 'click', function() {
          window.alert('Map was clicked!');
          // make ajax call here
        });
      }

Reference

【讨论】:

    【解决方案2】:

    按照这些步骤操作。

    1) 首先找到标记的点击事件。您可以在此文档中找到它。 链接:-https://developers.google.com/maps/documentation/javascript/examples/event-simple.

    2) 然后进行 ajax 调用,并将上面的PHP Code 放入您正在进行 ajax 调用的文件中。

    您可以使用以下函数找到标记的点击事件。

    var myCenter=new google.maps.LatLng(53, -1.33);
    
    var marker=new google.maps.Marker({
        position:myCenter,
        url: '/',
        animation:google.maps.Animation.DROP
    });
    
    function initialize()
    {
    var mapProp = {
        center:myCenter,
        zoom: 14,
        draggable: false,
        scrollwheel: false,
        mapTypeId:google.maps.MapTypeId.ROADMAP
    };
    
    var map=new google.maps.Map(document.getElementById("map-canvas"),mapProp);
    
    marker.setMap(map);
    }
    
    google.maps.event.addDomListener(window, 'load', initialize);
    google.maps.event.addListener(marker, 'click', function() {window.location.href = marker.url;});
    

    放一个分区,这样通过这个演示你就可以得到点击事件:-

    <div id="map-canvas"></div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 2017-10-23
      • 2014-03-17
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多