0

This question already has an answer here:

How can I find out the current location of the logged in user? When a user is logged in I just want to search the current location of user and save the lat and long in the database . How can I do that? Please help.

marked as duplicate by kiamlaluno May 27 '15 at 7:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You a use a geo IP database/service to lookup a lat/long based on the user's IP address. There are many PHP API's out there to do this. The most popular Drupal module based solution is Smart IP.

Smart IP identify visitor's geographical location (longitude/latitude), country, region, city and postal code based on the IP address of the user. These information will be stored at session variable ($_SESSION) with array key 'smart_ip' and Drupal $user->data object with array key 'geoip_location' of the user but optionally it can be disabled (by role) at Smart IP admin page. Other modules can use the function smart_ip_get_location($ip_address) that returns an array containing the visitor's ISO 3166 2-character country code, longitude, latitude, region (FIPS), city and postal code. It provides a feature for you to perform your own IP lookup and admin spoofing of an arbitrary IP for testing purposes.

Not the answer you're looking for? Browse other questions tagged or ask your own question.