Free GPS to Country/City Conversion on Android with BigDataCloud

Free GPS to Country/City Conversion on Android with BigDataCloud

bigdatacloud August 27, 2025

Share

As developers at BigDataCloud, we're thrilled to empower Android devs with seamless, free tools for location-aware apps. This guide walks you through converting GPS coordinates (latitude/longitude) to country and city names without any API keys or costs. We'll cover why our service shines, handling fallbacks, best practices, code examples, and even AI prompts to speed up your implementation. Let's dive in!

Why Choose BigDataCloud for Reverse Geocoding?

When your app doesn't require a full street address—just broader details like country or city—BigDataCloud's free reverse geocoding API is ideal. It delivers sub-millisecond responses with high accuracy, based on administrative boundaries. Unlike services demanding API keys or subscriptions, ours is truly anonymous and keyless, ensuring user privacy. No data is logged or tied to individuals, making it perfect for apps needing quick localisation, like weather widgets or region-specific content. Additionally, our API supports multilanguage locality names in over 100 world languages via the localityLanguage parameter, a unique feature not available in any other reverse geocoding service, even paid ones. Plus, it's unlimited for fair use, supporting both commercial and non-commercial projects.

IP Geolocation as a Smart Fallback

What if the user declines GPS access? Our free client-side reverse geocoding API now includes seamless IP geolocation fallback—also free! Simply call the same endpoint without latitude and longitude parameters, and it automatically estimates the user's location from their IP address, including country and city. This is powered by patented tech that detects proxies, bots, and roaming status, outperforming competitors in precision. The IP geolocation response is the same format as the reverse geocoding one, so it saves on transition and also ensures the same geographical names, as they may differ from provider to provider. It's GDPR-compliant and privacy-focused, enhancing UX in low-trust scenarios.

Understanding Our Fair Use Policy

Our free client-side API is designed for real-time, client-device calls only—not server-side or batch processing. Violations (e.g., calling from servers or using stored coords) may lead to IP bans. To avoid this during development—where you might test repeatedly or from emulators—we recommend using our server-side endpoint (Reverse Geocoding to City API) first. Sign up for a free account at www.bigdatacloud.com for 50,000 monthly queries (no credit card needed). Switch to the client-side endpoint (FREE Client Side Reverse Geocoding to City API) only in production for unlimited, keyless access. This keeps your dev workflow smooth and compliant. Full policy: fair use policy.

Prioritising Fine Location for Accuracy and Privacy

Always request ACCESS_FINE_LOCATION first—it's more precise (GPS/WiFi) than coarse (cell towers), yielding better city-level results. Use coarse only if fine is denied or unavailable, as it can be inaccurate (e.g., kilometres off). Since our API requires no keys, coordinates stay anonymous—no tracking or data retention. This anonymisation means fine location doesn't compromise privacy, unlike keyed services. In code, check permissions hierarchically: fine > coarse > IP fallback.

Code Snippets: Implementing in Android

Here's how to build this in Kotlin using FusedLocationProviderClient for location and OkHttp for API calls. Add dependencies: implementation 'com.google.android.gms:play-services-location:21.3.0' and implementation 'com.squareup.okhttp3:okhttp:4.12.0'.

Step 1: Get User Location


import android.Manifest
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices

private lateinit var fusedLocationClient: FusedLocationProviderClient

// In onCreate
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)

// Function to get location
fun getUserLocation(callback: (Double?, Double?) -> Unit) {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        fusedLocationClient.lastLocation.addOnSuccessListener { location ->
            callback(location?.
            latitude, location?.
            longitude)
        }
    } else if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        fusedLocationClient.lastLocation.addOnSuccessListener { location ->
            callback(location?.
            latitude, location?.
            longitude)
        }
    } else {
        // Request permissions here
        ActivityCompat.requestPermissions(
            this,
            arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION),
            1
        )
    }
}

Step 2: Reverse Geocode with Fallback


import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONObject

fun reverseGeocode(
    lat: Double? = null,
    lon: Double? = null,
    callback: (String, String) -> Unit
) {
    val client = OkHttpClient()
    var url = "https://api.bigdatacloud.net/data/reverse-geocode-client?localityLanguage=en"
    if (lat != null && lon != null) {
        url += "&latitude=$lat&longitude=$lon"
    }
    val request = Request.Builder().url(url).build()
    client.newCall(request).enqueue(object : okhttp3.Callback {
        override fun onFailure(call: okhttp3.Call, e: java.IOException) {
            /* Handle error */
        }
        override fun onResponse(call: okhttp3.Call, response: okhttp3.Response) {
            val json = JSONObject(response.body?.
            string())
            val country = json.getString("countryName")
            val city = json.optString("city", json.optString("locality", ""))
            callback(country, city)
        }
    })
}

Call it like: getUserLocation { lat, lon -> reverseGeocode(lat, lon) { country, city -> /* Use data */ } }

If lat/lon are null, it uses IP fallback seamlessly. Note: Adjusted parsing for "city" or "locality".

These snippets are async, error-resilient, and easy to integrate.

AI Prompts for Custom Code Generation

Leverage AI agents like Grok, ChatGPT, or Copilot to generate tailored code. Here are prompts:

  • For Kotlin: "Write Android Kotlin code using FusedLocationProvider to get fine/coarse location, then reverse geocode coords to country/city via https://api.bigdatacloud.net/data/reverse-geocode-client. If no location, omit lat/lon for IP fallback. Include permission handling."
  • For Java: "Generate Java code for Android to fetch user GPS (prefer fine, then coarse), use BigDataCloud free API for reverse geocoding if location available, else omit params for IP fallback. Use Volley for HTTP."
  • For Flutter (cross-platform): "Create Flutter Dart code to get device location with geolocator package, reverse geocode to city/country using BigDataCloud free client-side API, omitting coords for IP fallback if needed."
  • General: "Adapt this Kotlin snippet [paste code] to Swift for iOS, using BigDataCloud reverse geocoding API with IP fallback by omitting lat/lon."

Wrapping Up

With BigDataCloud, adding free, privacy-safe location conversion to your Android app is straightforward. Prioritise user consent, follow fair use, and test thoroughly. Questions? Reach us at support@bigdatacloud.com. Happy coding!

Share