Loading ...
Sorry, an error occurred while loading the content.

Sample PHP GeoCode code

Expand Messages
  • Tommy
    Hey everyone, I ve struggled with problem of pulling the X&Y coordinate from text via PHP and think that I have solved it. Hopefully, this code help others.
    Message 1 of 1 , Dec 11, 2008
    View Source
    • 0 Attachment
      Hey everyone,

      I've struggled with problem of pulling the X&Y coordinate from text via PHP and think that
      I have solved it. Hopefully, this code help others.

      Dan Theurer's blog post recommended using a proxy, but I prefer having a service that
      doesn't proxy and returns the data I want since the proxy can lead to people using your
      site for bad, bad things.

      http://www.theurer.cc/blog/2005/11/03/how-to-build-a-maps-mash-up/

      <?php
      $location = "Your Location";
      $appid = "Your APP ID";

      $request = 'http://api.local.yahoo.com/MapsService/V1/geocode';
      $request .= '?appid=' . $appid
      . '&location=' . rawurlencode( $location )
      . '&output=php';

      $session = curl_init($request);
      curl_setopt($session, CURLOPT_HEADER, false);
      curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
      $response = curl_exec($session);
      curl_close($session);

      $responseArray = unserialize($response);
      echo json_encode($responseArray['ResultSet']['Result']);

      ?>
    Your message has been successfully submitted and would be delivered to recipients shortly.