Because exact location requires user consent, it cannot be done with PHP. Try using JS to get the user's location and use AJAX to send it to the server.
If you are willing to use an approximate location, you can map by IP address. A web search will bring up a few options for that, such as this one.