SHARE
TWEET

Geotest: Germany/Grub am Forst

BakerMan Mar 21st, 2014 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter( 'the_content', 'geocode_test' );
  2.  
  3. function geocode_test( $content ) {
  4.         if ( ! isset($_GET['geotest'] ) ) return $content;
  5.         remove_filter( 'the_content', 'geocode_test' );
  6.  
  7.         $test_address = ' Lindenstrasse 5, Grub am Forst, 96271 Deutschland';
  8.         $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode( $test_address ) . '&sensor=false';
  9.  
  10.         $result = wp_remote_get($url);
  11.  
  12.         ob_start();
  13.         if ( isset( $result['body'] ) ) {
  14.                 $response = json_decode( $result['body'] );
  15.                 if ( isset( $response->results ) && isset( $response->results[0] )  && isset( $response->results[0]->geometry ) ) {
  16.                         echo "Geometry result:\n";
  17.                         var_dump( $response->results[0]->geometry->location );
  18.                 }
  19.                 else {
  20.                         echo "No geometry data\n";
  21.                 }
  22.         }
  23.         var_dump( $result );
  24.         $result = ob_get_clean();
  25.  
  26.         return '<pre>' . $result . '</pre>' . $content;
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top