File manager - Edit - /home/autoph/public_html/portal/web/locations.php
Back
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Live Demo of Google Maps Geocoding Example with PHP</title> <style> body{ font-family:arial; font-size:.8em; } input[type=text]{ padding:0.5em; width:20em; } input[type=submit]{ padding:0.4em; } #gmap_canvas{ width:100%; height:35em; } #map-label, #address-examples{ margin:1em 0; } </style> </head> <body> <?php error_reporting(0); if($_POST){ // get latitude, longitude and formatted address $data_arr = geocode($_POST['address']); $plate=$_POST['plate']; $trn=$_POST['trn']; // 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'><center>Map might shows approximate location only. Always check street and address.</center></div> <!-- JavaScript to show google map --> <script type="text/javascript" src="http://maps.google.com/maps/api/js?key=AIzaSyAGZxlxtyOO5Mev-Wz7lEmlr6g_jAkhkHI"></script> <script type="text/javascript"> function init_map() { var myOptions = { zoom: 18, 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."; } } ?> <div id='address-examples'> <div><b>Address:</b></div> <div><?php echo $_POST['address'];?></div> <?php if(isset($_POST['submita'])){ $plate=$_POST['plate']; $trn=$_POST['trn']; } ?> </div> <!-- enter any address --> <table style='width:100%'> <tr> <td colspan='2'> <form action="" method="post"> <input type='hidden' name='trn' value='<?php echo $trn;?>'> <input type='hidden' name='plate' value='<?php echo $plate;?>'> <input type='text' name='address' placeholder='Enter address here' style='width:100%;border:1px solid lightgray;height:30px;background:#F2F5A9' required/> </td> </tr> <tr> <td><input type='submit' value='Search Address'/></form></td> <td> <form action="mobile2.php" method="GET"> <input type='hidden' name='view' value='open'> <input type='hidden' name='trn' value='<?php echo $trn;?>'> <input type='hidden' name='plate' value='<?php echo $plate;?>'> <input type='submit' value='Home Page'/> </form> </td> </table> <?php // function to geocode address, it will return false if unable to geocode address 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; } } ?> </body> </html>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings