Hello,
Is there any module that can tell the default current location city of the user on their site.
Eg. if the user is accessing the site form pune it should display location -pune,if from mumbai display the location mumbai.

Comments

alinouman’s picture

First go and download php class for here http://ipinfodb.com/ip_location_api.php it will give you class ip2locationlite.class.php. Now in drupal custom module you can do this

   module_load_include('php', 'yourmodulename', 'ip2locationlite.class');
  $ipLite = new ip2location_lite;
  $ipLite->setKey('your api key you have to register free to get key');
//Get errors and locations
  $client_ip = ip_address(); //ip_address is drupal function
  $locations = $ipLite->getCity($client_ip);
  print 'City name'.$locations['cityName'];
subhajitfriend’s picture

You can use Google API for the location access via IP.

Anuprita Sapate’s picture

Where should i actually paste this code?
I created a custom module name 'ip2locationlite' an extracted the file that u said.
Am i going right???

alinouman’s picture

you have create module name ip2locationlite. Now Put that class(ip2locationlite.class.php) which you had download in module directory
put this code in ip2locationlite.module file

function ip2locationlite_init() { 
 module_load_include('php', 'ip2locationlite', 'ip2locationlite.class');
  $ipLite = new ip2location_lite;
  $ipLite->setKey('your api key you have to register free to get key');
//Get errors and locations
  $client_ip = ip_address(); //ip_address is drupal function
  $locations = $ipLite->getCity($client_ip);
  print 'City name'.$locations['cityName'];
}

also clear the cache.

Anuprita Sapate’s picture

do i have to register for api key??
It is displaying-'City name' not the actual city name
In the above code and line $ipLite->setKey('your api key you have to register free to get key');
Do i have to register for instering here api key???

alinouman’s picture

yes u have to register for the api key and insert that key in setkey function.

Anuprita Sapate’s picture

after registration for the key also the actual city name is not being displayed.Can u tell what could be the problem??

alinouman’s picture

r u testing on localhost? plz test the code on live server it will work on live server.

Anuprita Sapate’s picture

Yes i were testing on localserver.
Ok thx i'll check on live server