Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将php页面中的邮政编码或地址与google地图匹配_Javascript_Php_Ajax_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 将php页面中的邮政编码或地址与google地图匹配

Javascript 将php页面中的邮政编码或地址与google地图匹配,javascript,php,ajax,google-maps,google-maps-api-3,Javascript,Php,Ajax,Google Maps,Google Maps Api 3,我有一个PHP页面,其中某个人的地址从数据库表中读取 比如: Person name address zip MAP MR. xyz city1 1234 click MR. abc city2 1234 click MR. dfe city3 1244 click MR. rrr city4 1284 click 如果管理员点击abc先生的点击按钮,则谷歌地图应打开abc先生的地址或邮政编码

我有一个PHP页面,其中某个人的地址从数据库表中读取

比如:

Person name  address  zip     MAP

MR. xyz      city1    1234    click
MR. abc      city2    1234    click
MR. dfe      city3    1244    click
MR. rrr      city4    1284    click
如果管理员点击abc先生的点击按钮,则谷歌地图应打开abc先生的地址邮政编码,谷歌位置应打开abc先生的谷歌地图

我不知道怎么做?请提出一些建议

现在我发现了一个代码:

 <?php
include("connection.php");

 function geocode($address){

   // url encode the address
  $address = urlencode($address);

  // google map geocode api url
  $url = "http://maps.google.com/maps/api/geocode/json?address={$address}";

  // get the json response
  $resp_json = file_get_contents($url);

  // decode the json
  $resp = json_decode($resp_json, true);

    // response status will be 'OK', if able to geocode given address 
   if($resp['status']=='OK'){

    // get the important data
    $lati = $resp['results'][0]['geometry']['location']['lat'];
    $longi = $resp['results'][0]['geometry']['location']['lng'];
    $formatted_address = $resp['results'][0]['formatted_address'];

    // verify if data is complete
    if($lati && $longi && $formatted_address){

        // put the data in the array
        $data_arr = array();            

        array_push(
            $data_arr, 
                $lati, 
                $longi, 
                $formatted_address
            );

        return $data_arr;

    }else{
        return false;
    }

    }else{
    return false;
  }
 }


  if($_REQUEST){

   // get latitude, longitude and formatted address
   $data_arr = geocode($_REQUEST['address']);

    // if able to geocode the address
   if($data_arr){

    $latitude = $data_arr[0];
    $longitude = $data_arr[1];
    $formatted_address = $data_arr[2];

   ?>

    <!-- google map will be shown here -->
   <div id="gmap_canvas">Loading map...</div>
   <div id='map-label'>Map shows approximate location.</div>

   <!-- JavaScript to show google map -->
    <script type="text/javascript" src="http://maps.google.com/maps/api/js"></script>    
    <script type="text/javascript">
    function init_map() {
        var myOptions = {
            zoom: 14,
            center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
        marker = new google.maps.Marker({
            map: map,
            position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>)
        });
        infowindow = new google.maps.InfoWindow({
            content: "<?php echo $formatted_address; ?>"
        });
        google.maps.event.addListener(marker, "click", function () {
            infowindow.open(map, marker);
        });
        infowindow.open(map, marker);
    }
    google.maps.event.addDomListener(window, 'load', init_map);
    </script>

    <?php

    // if unable to geocode the address
    }else{
    echo "No map found.";
   }
   }

   ?>

     But it gave an ERROR:  **Map shows approximate location.** 

正在加载地图。。。
地图显示了大概的位置。
函数init_map(){
变量myOptions={
缩放:14,
中心:新google.maps.LatLng(,),
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“gmap_画布”),myOptions);
marker=新的google.maps.marker({
地图:地图,
位置:新的google.maps.LatLng(,)
});
infowindow=新建google.maps.infowindow({
内容:“”
});
google.maps.event.addListener(标记“单击”,函数(){
信息窗口。打开(地图、标记);
});
信息窗口。打开(地图、标记);
}
google.maps.event.addDomListener(窗口'load',初始化映射);
但它给出了一个错误:*地图显示了大致位置。**

代码对不对

您只需在谷歌地图url中添加地址和邮政编码,然后在新选项卡中打开即可。URL可以如下所示

http://maps.google.com/maps?q=<address>+<zip>

http://maps.google.com/maps?q=Delhi+110021
http://maps.google.com/maps?q=+
http://maps.google.com/maps?q=Delhi+110021

您可以共享的任何现有代码?您需要使用Google的地理编码API来确定地图上的位置,使用PHP和/或JS。请阅读此感谢您的回复。我没有任何代码,因为我不知道如何启动它?这是一种非常常见的情况,如果您搜索Google Maps API PHP,您应该能够找到大量的示例/教程,或者查看以下内容:感谢您回复cloudsoft technology的显示结果,绘图编号9,zone-1,mp nagar bhopal 462011。未发现mp nagar bhopal462011第1区9号地块cloudsoft technology的结果。