Google Map Droplet

jacobi22


Hans

Thank you, works perfect!
Hans
Hans - Nijmegen - The Netherlands

mdemaree99

Droplet for Google Maps that does not require an API Key

Can change address, zoom, height and width.
Default zoom: 14
Width:  500
Height:  500


[[GoogleMap?address=The White House 1600 Pennsylvania Ave NW Washington DC&zoom=14&zoom=14&width=500&height=500]]


if (!isset($zoom)) $zoom=14;
if (!isset($width)) $width=500;
if (!isset($height)) $height=500;

$data = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($address)."&sensor=false");
$obj = json_decode($data);
  if ($obj) {
    if (isset($obj->results[0]->geometry->location)) {
      $loc = $obj->results[0]->geometry->location;
      $array = array('latitude'=>$loc->lat, 'longitude'=>$loc->lng);
     $string_address = implode(',', $array);
    } else {
      throw new Exception('Lookup failed and/or address does not exist!');
    }
  } else {
    throw new Exception('Lookup failed and/or address does not exist!');
  }

echo'
<style>
       #map_canvas {
        margin: 0;
        padding: 0;
        height:'.$height .';
        width:'.$width .'
      }
</style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
      function initialize() {
        var mapOptions = {
          zoom: '. $zoom .',
          center: new google.maps.LatLng(' . $string_address .'),
          mapTypeId: google.maps.MapTypeId.ROADMAP};       
          map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
          var marker = new google.maps.Marker({ position: new google.maps.LatLng(' . $string_address .') , map: map });         
           }
google.maps.event.addDomListener(window, "load", initialize);
    </script>';
return '<div id="map_canvas"></div>';