Reputation: 147
I get latitude and longitude values as geocoder results by using codes I got from http://www.phpmoot.com/php-get-latitudelongitude-from-an-address-with-google-map/. What I want is setting the results to have just two digits behind the ".". For example 137.3463566 to be 137.34. Is there any way to do this?
Upvotes: 1
Views: 584
Reputation: 9407
Same as this answer. You cannot control what Google sends you, but you can discard what you don't need.
you can use toFixed(), as in
var lat = map.getCenter().lat().toFixed(2); // keep only 2 decimals
var lon = map.getCenter().lng().toFixed(2); // keep only 2 decimals
and if you want to round it on the PHP side:
$lat = round($output->results[0]->geometry->location->lat,2);
$long = round($output->results[0]->geometry->location->lng,2);
Upvotes: 2