XF 2.1 How to convert Address in Custom Thread Field to Coordinates (Lat Long)?

gogo

Well-known member
I want to create a CTF to let user to input an address. Then I want to show the converted Coordinates in the post as $lat, $long.

Is it possible?
 
Yes I got an API for that. And I got the following code from Stackflow:

PHP:
<?php
     // Get lat and long by address         
        $address = $dlocation; // Google HQ
        $prepAddr = str_replace(' ','+',$address);
        $geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
        $output= json_decode($geocode);
        $latitude = $output->results[0]->geometry->location->lat;
        $longitude = $output->results[0]->geometry->location->lng;

?>

But how do I use it?
 
Back
Top Bottom