Sami El Hilali
Sami El Hilali

Reputation: 1041

PHP How to get the full longitude and the latitude using google API

Please I have made this code to get the longitude and the latitude :

$addresss = "France+mande-lieu-la-napol";
$region   = "Alpes-Maritimes";
$urll      = "http://maps.google.com/maps/api/geocode/json?address=$addresss&sensor=false&region=$region";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urll);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);

var_dump ($response_a->results[0]->geometry->location->lat );

var_dump ( $response_a->results[0]->geometry->location->lng );

This code gives me as result :

float(43.546232) float(6.938309)

But in real it must give me

float(43.546232) float(6.938309000000004) 

Please what should I do to get the full longitude ?

Upvotes: 2

Views: 1167

Answers (1)

Mark S.
Mark S.

Reputation: 4017

You should use json_decode($json, true, 512, JSON_BIGINT_AS_STRING) so that the lat and long will be returned as strings instead of floats.

Upvotes: 1

Related Questions