Guest User

Untitled

a guest
Oct 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2. function getCoordinates($address) {
  3.  
  4. $address = urlencode($address);
  5.  
  6. // set HTTP header
  7. $headers = array('Content-Type: application/json');
  8.  
  9. // Open connection
  10. $curl = curl_init();
  11. curl_setopt($curl, CURLOPT_URL, 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=' . $address);
  12. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  13. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  14.  
  15. // Execute request
  16. $result = curl_exec($curl);
  17.  
  18. // Close connection
  19. curl_close($curl);
  20.  
  21. // get the result and parse to JSON
  22.  
  23. $json = json_decode($result);
  24.  
  25. $lat = $json->results[0]->geometry->location->lat;
  26. $lng = $json->results[0]->geometry->location->lng;
  27.  
  28. return array($lat, $lng);
  29.  
  30. }
  31.  
  32. $coords = getCoordinates("ADDRESS GOES HERE ");
  33. $coords = join(',', $coords);
  34.  
  35. ?>
  36.  
  37. <?php the_title(); ?>, <?php if( get_field('address_line_1') ): ?><?php the_field('address_line_1', $post_id); ?><?php endif; ?>,<?php if( get_field('address_line_2') ): ?><?php the_field('address_line_2', $post_id); ?><?php endif; ?>, <?php if( get_field('town') ): ?><?php the_field('town', $post_id); ?><?php endif; ?>, <?php if( get_field('post_code') ): ?><?php the_field('post_code', $post_id); ?><?php endif; ?>, <?php if( get_field('country') ): ?><?php the_field('country', $post_id); ?><?php endif; ?>
Add Comment
Please, Sign In to add comment