Google Maps - samuelgrant/fight-for-kidz GitHub Wiki

Google Maps API:

This application uses Google Maps library alexpechkarev/google-maps on the index page to display the location of the event

Setting up the Map API:

Offical Documentation: Google Maps, Geo Coding | alexpechkarev/google-maps

GOOGLE_MAPS_KEY={API key FROM GOOGLE}

Geocoding Usage:

We recommend keeping the geocode lookup in it's own function. This can be a static helper or part of a normal class.

The geocode lookup takes a string that can be either a mailing address or the name of a well known building. For example 230 Tay street or SIT Invercargill.

public function getGPS($address){
        $response = \GoogleMaps::load('geocoding')
        ->setParam (['address' => $address])->get();
        $json = json_decode($response, TRUE);

        return ('lat: '.$json['results'][0]['geometry']['location']['lat'].", lng: ".$json['results'][0]['geometry']['location']['lng']);  
    }

Google Maps Usage:

The map uses the venue_gps field to get the correct location to be displayed on the map

<div id="map" style="width:100%; height: 450px; border:0"></div>
   <script>
      function initMap() {
          var uluru = { {{$event->venue_gps}} };
          var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 15,
          center: uluru
          });
          var marker = new google.maps.Marker({
          position: uluru,
          map: map
          });
      }
  </script>
  
  <script async defer
      src="https://maps.googleapis.com/maps/api/js?key={{env('GOOGLE_MAPS_KEY')}}&callback=initMap">
  </script>
               
⚠️ **GitHub.com Fallback** ⚠️