Dude.. seriously, google. :) https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=php%20geolocation%20api
Nothing built into laravel, no. Find a PHP solution you like and use it.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Is there API of Laravel to determine the geographical location of website visitors ??
Dude.. seriously, google. :) https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=php%20geolocation%20api
Nothing built into laravel, no. Find a PHP solution you like and use it.
@willvincent dude pls if u have no positive contribution pls keep to yourself pls
You really felt it necessary to revive a 6yr old thread to try and put me in my place? 🙄

There is package for it: https://github.com/Torann/laravel-geoip
pretty straightforward
Not sure how up to date that database is but I use an API for it. Not always the best idea since it could go down but this keeps it updated http://dazzlepod.com/ip/me.json
Also, if you use CloudFlare, you can pick it up via $_SERVER["HTTP_CF_IPCOUNTRY"]; https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-CloudFlare-IP-Geolocation-do-
@getnathan have a look at this https://github.com/geocoder-php/StackGeoIp
I've used laravel-geoip in 4.2, I believe it's now updated to support L5. It uses the Maxmind database and I've found it to be pretty accurate.
https://github.com/Torann/laravel-geoip
You might also be interested in this: http://diveintohtml5.info/geolocation.html
Thanks for this amazing support! @sitesense, @brayniverse, @bashy, @Viking, @blackbird and @willvincent => thank you !
My idea is to connect to a local database and bring location specific data to the user. Backend is laravel and front end is angularjs.
So when user visits the page I need to know users geolocation lat and long data first. Using that lat and long data I am going to reverse geocode to find the user's postcode. Then I will connect the database to fetch the data related to that postcode.
Although modern browsers are capable of detecting geolocation lat and long data of incoming request I tend to hand over that task to backend; otherwise I have to wait until front end fetches user's gelocation and then give it to back end. If there is a way to send the user's geolocation with the initial request then I can access it from a superglobal varaible at the back end and fetch the data accordingly. But, I don;t think it is possible. So I think letting backend to do the whole job makes an easy process. Since Laravel request starts at the routes.php I can initiate whole process right there without waiting until the front end browser picks the geolocation and send that data to back end. In my approach I will have to use user's IP address to find the user's location though.
I would love to hear your thoughts on this.
When I try to install Torann/laravel-geoip it throws an error message saying .... Installing dependencies (including require-dev) from lock file Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them. Nothing to install or update Generating autoload files Generating optimized class loader
And after that couldn't follow rest of the process since it gave me errors
I will try to copy across manually.
'I would love to hear your thoughts on this.'
I did something very similar to that in my old project. In a future project that I have in mind, I'll be thinking about using both the backend and frontend approach. Backend to get a rough location and frontend to pinpoint as close as possible.
Especially with mobile devices, if you need more accuracy of the user's current, actual location, you can't be relying on ip address alone.
Postcode will only be based on the IP, not the user's location. You know that?
@sitesense thanks for your thoughts. @bashy - really I didn't know that. I am glad you told me it.
@sitesense, according to @bashy, no point of using geolocation using front end isn't it? Please correct me if I am wrong. Since post code is based on IP address (not the user location) it may be a good idea to use GeoIP (https://github.com/Torann/laravel-geoip) as it utilises IP address as my whole aim is to get the user;s postcode.
By the way you guys are amazing... and thanks lot for your inputs. It gave me really good start on this.
By the way the error message I got when I try to install GeoIP was related to my broken composer lock file. So I deleted vendor folder and composer lock file and called composer install and then installed GeoIP successfully after that.
@getnathan of course it depends how accurate you need to be :)
IP addresses and their relation to a particular latitude/longitude, are guesswork in some cases and not always that accurate. Saying that, I've had decent results from the MaxMind database.
Edit:
As an example, a known user in France connecting via Orange broadband had dynamic IP addresses that would change every few days. This user could be reported as being in different cities 100's of miles apart.
You can get close, sure. As sitesense said, it's really down to what you're using it for. If you were using it to generate a postcode for delivery... that wouldn't be a good idea :P
@sitesense and @ bashy sorry I forgot to tell you that it has to be 100% accurate.
I need to find a way to get exact postcode of user with 100% accuracy.
I used GeoIP (https://github.com/Torann/laravel-geoip) few mintes ago and it gave me wrong post code for my IP. I used MaxMind db.
I live in Melbourne Australia.
@getnathan as another example, go to this site but ignore the request for "computer's location" (don't allow):
On the map, "click for more details". You should now see your postcode in the new page. Mine is wrong.
Now below the map on this page, click "Update IP Location" and allow the browser to determine your location.
You'll be presented with another map with other locations by different "Providers" listed below it. Check out the W3C location and this is probably far more accurate than the others.
The W3C Geolocation service determines location by the browser providing GPS location (if available) and signal strengths of visible WiFi annoucements.
... and regarding accuracy, this is a good read:
http://whatismyipaddress.com/geolocation-accuracy
The only way to get 100% accuracy (or close) would be to allow the user to adjust your own estimate.
@sitesense , "more details" in http://whatismyipaddress.com/ gave a wrong result for my postcode too. And then W3C didn't even listed my postcode while provider A gave me a bit close result. amazing...
Compared to all of that maxmind gave me fairly close result.
Have a look at this link https://www.maxmind.com/en/geoip2-city-database-accuracy. According to it Australia is only 67% accurate.
@sitesense thanks for the link. All of you guys gave me amazing info and I should thank all of you immensely for that.
@getnathan although the W3C doesn't list the postcode, take a look at the map location. Mine was within a few metres. You could then use the lat/long provided by the browser to more accurately determine the postode.
Edit:
Some more in-depth info - http://www.andygup.net/html5-geolocation-api-%E2%80%93-how-accurate-is-it-really/
@sitesense I went back and checked it agian and I found that you are correct as W3C's location data was pretty accurate. But according to @bashy I still have to go with my IP address to get post code. isnt' it? Because I have to find a way to convert ip address or lat/long to postcode.
@getnathan no, @bashy was pretty much saying the opposite. He means the IP address is almost useless to determine location with any accuracy.
If you have the lat/lng, you can find the postcode in many ways. Probably the easiest is with the Google Geocoding Api:
https://developers.google.com/maps/documentation/geocoding/#geocoding
Edit: This is what can be achieved - enter your lat/lng into this site - it gave my next door neighbour's full address!
Geo Location by my IP address places me 60 miles away from my actual location. If I allow Google to access my location, and try to pull it up on the map, on my laptop, it places me within a few hundred yards of my actual location. Presumably this is because it's based on my mobile phone location:
If you have Location History turned on, your location may be based on the location of your mobile device.
At any rate, geolocation by ip is not terribly reliable or accurate.
There's also this: https://github.com/stevebauman/location
Another alternative package for consideration: https://github.com/ip2location/ip2location-laravel
Support the below return result:
Thank you. Is this location comes from the client site?
I can recommend the following PHP package from ipbase.com.
Please or to participate in this conversation.