Ipdata.co provides a scalable API to do this. With 10 global endpoints each able to handle >800M requests daily!
It also gives you the organisation, currency, timezone, calling code, flag and Tor Exit Node status data from any IPv4 or IPv6 address.
In php
php > $ip = '8.8.8.8';
php > $details = json_decode(file_get_contents("https://api.ipdata.co/{$ip}"));
php > echo $details->region;
California
php > echo $details->city;
Mountain View
php > echo $details->country_name;
United States
php > echo $details->location;
37.405991,-122.078514
Disclaimer
I built this service.