php get latitude from address without api key
php get latitude from address without api key
I have function that get address and return latitude and longitude.
The problem is that after a while i'm getting 0.00000 for both lat & lng. I guess that i need to add "&key=API_KEY" to the url, and if i got it right it's cost money.
Is there any other way to get address lat & lng ?
function get_address_lat_lng ($address)
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.urlencode($prepAddr).'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$lng = $output->results[0]->geometry->location->lng;
return (array('lat' => $lat, 'lng' => $lng) );
@scaisEdge - hi. so why do i get 0.0000 for lat & lng? I don't have lot of traffic...
– Roi
Sep 2 at 11:56
you have not apikey .. so you have not result .. you must have a valid apikey
– scaisEdge
Sep 2 at 11:57
1 Answer
1
function ipLookUp ()
$.ajax('http://ip-api.com/json')
.then(
function success(response)
console.log('User's Location Data is ', response);
console.log('User's Country ', response.country);
,
function fail(data, status)
console.log('Request failed. Returned status of ', status);
);
ipLookUp()
Check your console logs on browsers but this is based on IP of client.
I think you confuse with the topic....
– Roi
Sep 2 at 11:55
thats right , from address !! i will edit it soon
– Ahmed Shahin
Sep 2 at 11:58
@AhmedShahin : while you are rethinking your answer, consider that your php looks a lot like js.
– YvesLeBorg
Sep 2 at 12:07
you can write javascript and call it in php ... do you want me to make live example ?
– Ahmed Shahin
Sep 2 at 12:08
@AhmedShahin - Hi there. Your script return latitude and longitude by user location. I need it by address...
– Roi
Sep 2 at 15:17
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
for reistered user (for obtain google key) google maps new policies .. give a free amount each month for some operation check google maps site for this ..
– scaisEdge
Sep 2 at 11:40