SHOW:
|
|
- or go back to the newest paste.
| 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 = '3100 Central Ave (at Fountain) ALAMEDA CA CA United Statese'; |
| 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 | } |