Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dev0ps's avatar

How to obtain latitude and longitude of user

0 likes
9 replies
click's avatar

You could do it with by passing the IP of the user to an API that will return you the latitute and longitude.

There are several services that offer this. Some of them are free with a maximum amount of calls per month and some of them are paid.

Just two of them

You can get the ip of the user with:

request()->ip(); 
// or
Request::ip(); 
Snapey's avatar

bear in mind that pulling it from IP address is about as accurate as asking the user what country they are in.

1 like
click's avatar

True that (and also good that it is not more accurate). But it is the most accurate you can get (as far as I know). And looking at the API the OP wants to use (weather) it is should not be a problem.

Dev0ps's avatar

Is there any API that automatically detects user current location and display weather forecast because these two methods are not exactly identify user current location.

Please or to participate in this conversation.