2016-11-11 2 views
0

Ich habe eine Datenbank auf phpadmin erstellt und ich habe Informationen aus einer XML-Datei in die Datenbank extrahiert, mein Datenbankfeld besteht aus Zeit, Breite, Länge, Tiefe und Magnitude.i haben eine Tabelle mit allen Informationen auf einer Webseite und ich habe ein Feld mit einem Link, während ich auf den Link klicke, sollte es mich zu einer Google Map API leiten und es muss die Breiten- und Längeninformationen aus der Datenbank extrahieren, in der ich das Problem habe geben Sie den Wert der Breite und Länge automatisch, jedes meinen Code des help.hereÜbergeben von Werten mit einer 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> 

dies mein ist 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> 
+0

Sie entfernen besser Ihren API-Schlüssel aus der Frage. –

Antwort

0

In der HTML-Seite können Sie Breiten- und Längengrad einfach als Abfragezeichenfolge übergeben.

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

Um die gleiche Breite und Länge erhalten nur das Skript mit der GET Anfrage aktualisieren.

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

Ich habe die Anfrage erhalten, aber es funktioniert nicht. Funktion initmap() { var myLatLnh = {lat: "", Lng: "" }; usw. ..... @HappyCoding – fairytale

+0

@fairytale, welches Problem Sie konfrontiert sind –

0

Sie können geolocation api direkt von PHP verwenden.

Sie können eine URL wie folgt aufrufen:

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

Und eine strukturierte json Antwort wie diese erhalten:

{ 
    "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" 
} 

Sie diesen Anruf curl mit tun können.

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

Verwandte Themen