Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getCoordinates($address) {
- $address = urlencode($address);
- // set HTTP header
- $headers = array('Content-Type: application/json');
- // Open connection
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=' . $address);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- // Execute request
- $result = curl_exec($curl);
- // Close connection
- curl_close($curl);
- // get the result and parse to JSON
- $json = json_decode($result);
- $lat = $json->results[0]->geometry->location->lat;
- $lng = $json->results[0]->geometry->location->lng;
- return array($lat, $lng);
- }
- $coords = getCoordinates("ADDRESS GOES HERE ");
- $coords = join(',', $coords);
- ?>
- <?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