WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Google Map Droplet
  • Print
Pages: [1]   Go Down

Author Topic: Google Map Droplet  (Read 9119 times)

Offline mdemaree99

  • Posts: 102
Google Map Droplet
« on: May 03, 2014, 05:15:05 PM »
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]]

Code: [Select]
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>';
Logged

Offline Hans

  • Posts: 914
  • Gender: Male
Re: Google Map Droplet
« Reply #1 on: May 04, 2014, 09:10:39 AM »
Thank you, works perfect!
Hans
Logged
Hans - Nijmegen - The Netherlands

jacobi22

  • Guest
Re: Google Map Droplet
« Reply #2 on: May 05, 2014, 03:33:18 PM »
thanks for sharing!
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Google Map Droplet
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2