2016-11-11 1 views
0

phpadmin에서 데이터베이스를 만들었고 XML 파일에서 데이터베이스로 정보를 추출했습니다. 데이터베이스 필드는 시간, 위도, 경도, 깊이 및 진도로 구성됩니다 .i 모든 테이블을 표시하는 테이블이 있습니다. 웹 페이지에 대한 정보 및 링크가 포함 된 입력란이있는 링크를 클릭하면 Google지도 API로 연결되고 데이터베이스에서 위도와 경도 정보를 추출해야합니다. 어떤 help.here의 내 코드 자동href를 사용한 값 전달

<?php 
    require('dbconnect.php'); 
    $query="SELECT * from earthquake_xml"; 
    $result= mysqli_query($dbc,$query); 
    echo "Query Executed Successfully "; 
    $numRow =mysqli_num_rows($result); 
    echo "<br> Number Of Rows:".$numRow; 
?> 
<!DOCTYPE HTML> 
<html> 
<head> 
    <style> 
    table, th, td { 
    border: 1px solid black; 
    padding:10px; 
} 
table{ 
    border-collapse: collapse; 
    text-align:center; 

} 
    </style> 
</head> 
<body> 
<table> 
    <tr> 
     <td>Time</td> 
     <td>Latitude</td> 
     <td>Longitude</td> 
     <td>Depth</td> 
     <td>Magnitude</td> 
     <td>Google Map </td> 
    </tr> 
    <?php 
    if($numRow>0) 
    { 
     while($row=mysqli_fetch_assoc($result)) 
     { 
      echo "<tr>"; 
      echo "<td>" .$row['Time'] . "</td>"; 
      echo "<td>" .$row['Latitude']. "</td>"; 
      echo "<td>" .$row['Longitude']. "</td>"; 
      echo "<td>" .$row['Depth']. "</td>"; 
      echo "<td>" .$row['Magnitude']. "</td>"; 
      echo "<td><a href='googleMap.php?longitude= '' '>Click here</a></td>"; 
      echo "</tr>"; 

     } 




    } 

    ?> 

</table> 

</body> 
</html> 

를 위도와 경도의 값이 내 googleMap.php

<!DOCTYPE HTML> 
<HTML> 
<head> 
<title></title> 
<style> 
html,body{ 
    height:100%; 
    margin:0; 
    padding:0; 
} 
#map{ 
    height:100%; 
} 
</style> 
</head> 
<body> 
<div id="map"></div> 
<script> 
function initMap(){ 
    var myLatLng={lat:-36.5806,lng:-73.6355}; 
    var map=new google.maps.Map(document.getElementById('map'),{ 
    center:myLatLng, 
    zoom:8 
    }); 

    if(navigator.geolocation){ 
     navigator.geolocation.getCurrentPosition(function(position){ 
      var pos={ 
       lat:-36.5806, 
       lng:-73.6355 
      }; 

      var marker=new google.maps.Marker({ 
       position:pos, 
       map:map, 
      }); 

      map.setCenter(pos,marker) 
     },function(){ 
      handleLocationError(true,map.getCenter()); 
     }); 
    }else{ 
     handleLocationError(false,map.getCenter) 
    } 
} 
</script> 
<script async defer 
src="https://maps.googleapis.com/maps/api/js?key=&callback=initMap"> 
</script> 
</body> 

</html> 
012,351되어 통과
+0

질문에서 api 키를 제거하는 것이 좋습니다. –

답변

0

HTML 페이지에서 위도와 경도를 쉽게 쿼리 문자열로 전달할 수 있습니다.

echo "<td><a href='googleMap.php?longitude=".$row['longitude']."&latitude=".$row['latitude']."'>Click here</a></td>"; 

그냥 GET 요청과 함께 스크립트를 업데이트 같은 위도와 경도를 얻으려면.

function initMap(){ 
    var myLatLng={lat:'<?php echo $latitude ?>',lng:'<?php echo $longitude?>'}; 
    ....// so on 
} 
+0

get 요청을 사용했지만 작동하지 않습니다. 함수 initmap() { var myLatLnh = {lat : "", lng : "" }; 등 ..... @HappyCoding – fairytale

+0

@fairytale 무슨 문제가 있습니까? –

0

PHP에서 직접 geolocation api를 사용할 수 있습니다.

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

을 그리고 이와 같은 구조화 된 JSON 응답 나타납니다 :

는이 같은 URL을 호출 할 수 있습니다

{ 
    "results" : [ 
     { 
     "address_components" : [ 
      { 
       "long_name" : "1600", 
       "short_name" : "1600", 
       "types" : [ "street_number" ] 
      }, 
      { 
       "long_name" : "Amphitheatre Parkway", 
       "short_name" : "Amphitheatre Pkwy", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Mountain View", 
       "short_name" : "Mountain View", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Santa Clara County", 
       "short_name" : "Santa Clara County", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "California", 
       "short_name" : "CA", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "Stati Uniti", 
       "short_name" : "US", 
       "types" : [ "country", "political" ] 
      }, 
      { 
       "long_name" : "94043", 
       "short_name" : "94043", 
       "types" : [ "postal_code" ] 
      } 
     ], 
     "formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, Stati Uniti", 
     "geometry" : { 
      "location" : { 
       "lat" : 37.4223664, 
       "lng" : -122.084406 
      }, 
      "location_type" : "ROOFTOP", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 37.4237153802915, 
        "lng" : -122.0830570197085 
       }, 
       "southwest" : { 
        "lat" : 37.42101741970851, 
        "lng" : -122.0857549802915 
       } 
      } 
     }, 
     "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA", 
     "types" : [ "street_address" ] 
     } 
    ], 
    "status" : "OK" 
} 

당신은 컬을 사용하여이 전화를 할 수 있습니다.

Ref. https://developers.google.com/maps/documentation/geocoding/start