URL and Link repository

Thursday, July 9, 2015

Google Maps API

Last night while testing the features of SpiderOnFire, I found that step 2 Mark stopped working. After adding an echo,I realized that my call to the maps API using the clever key "abcdefg" stopped working after years of service.

A quick visit to google developers console allowed me to properly define a key associated with this project: Widespread Augmented Reality

Get one for yourself be following these steps:

  • Find APIs&Auth in left pane
  • Select APIs
  • Create key for browser
  • Select credentials in left pane to verify
  • Copy key into your web page code
  • Example:
    define("MAPS_HOST", "maps.google.com");
    define("KEY", "AIzaSyC6Fhp2Q78tcAf3FVmkY--xxxxxxxxx");
    $base_url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" ;
       $location = $_POST['latlng'];
       $location = substr($location,1,-1);
       $location = str_replace(" ","",$location); 
       $emd_url =  "&sensor=false" ;
       $request_url = $base_url . $location . $emd_url;
       $jsoncontents = file_get_contents($request_url) ;
       $decodedjson = json_decode($jsoncontents);
       $formattedaddy= $decodedjson->results[0] -> formatted_address;

    No comments:

    Post a Comment