get region/city from ip

http://ipinfo.io, my service, gives you city, country and other related information about an IP:

$ curl ipinfo.io/8.8.8.8
{
  "ip": "8.8.8.8",
  "hostname": "google-public-dns-a.google.com",
  "loc": "37.385999999999996,-122.0838",
  "org": "AS15169 Google Inc.",
  "city": "Mountain View",
  "region": "CA",
  "country": "US",
  "phone": 650
}

Here's a PHP example:

$details = json_decode(file_get_contents("http://ipinfo.io/".$_SERVER['REMOTE_ADDR']"));
echo $details->city; // -> "Mountain View"

Free Geolocation API http://ip-api.com/docs/

You can get information about your ip-address, country, region, city, isp, organization.

Response formats and examples: XML, JSON, CSV, PHP.

Usage limits: Our system will automatically ban any IP addresses doing over 240 requests per minute.

PHP Example

$ip = $_SERVER['REMOTE_ADDR']; 
$query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
if($query && $query['status'] == 'success') {
echo 'My IP: '.$query['query'].', '.$query['isp'].', '.$query['org'].', '.$query ['country'].', '.$query['regionName'].', '.$query['city'].'!';
} else {
echo 'Unable to get location';
}