Hi habe ein Problem, dass ich nicht gelöst bekomme. Mein unten stehendes Skript zeigt mir keine Karte an, findet jemand hier den Fehler, angeblich sollte es funktionieren :/
Vielen Dank schon mal im Vorraus!
Gruß Nils
<?php
// if unable to geocode the address
}else{
echo "No map found.";
}
}
?>
</html>
[/HTML]
Vielen Dank schon mal im Vorraus!
Gruß Nils
HTML-Code:
<!DOCTYPE html> <html> <head> </head> <body> <form action="" method="post"> <input type='text' name='address' placeholder='Enter any address here' /> <input type='submit' value='Geocode!' /> </form> <?php function geocode($address){ $address = urlencode($address); $url = "http://maps.google.com/maps/api/geocode/json?address={$address}"; ; $resp_json = file_get_contents($url); $resp = json_decode($resp_json, true); if($resp['status']=='OK'){ $lati = $resp['results'][0]['geometry']['location']['lat']; $longi = $resp['results'][0]['geometry']['location']['lng']; $formatted_address = $resp['results'][0]['formatted_address']; if($lati && $longi && $formatted_address){ $data_arr = array(); array_push( $data_arr, $lati, $longi, $formatted_address ); return $data_arr; }else{ return false; } }else{ return false; } } ?> </body> <?php if($_POST){ // get latitude, longitude and formatted address $data_arr = geocode($_POST['address']); // if able to geocode the address if($data_arr){ $latitude = $data_arr[0]; $longitude = $data_arr[1]; $formatted_address = $data_arr[2]; ?> <div id="gmap_canvas">Loading map...</div> <div id='map-label'>Map shows approximate location.</div> <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>
// if unable to geocode the address
}else{
echo "No map found.";
}
}
?>
</html>
[/HTML]
Kommentar