what problem i am actually facing is that .. i have a database -- table in which i have lng and lat saved .. And i want that when i fetch them in textual form i also get the address to which those particular set of lng and lat are defined ..

Is there any straight forward way to get this ?? I dont need to plot them on map .. just in textual format .

Dani AI

Generated

Reverse geocoding (lat/lon -> human address) is a solved problem: commercial providers (Google, Mapbox, HERE, etc.) and free services based on OpenStreetMap (Nominatim) can return a formatted address for given coordinates. was right to flag the practical issue: many nearby points map to the same address, so calling an API for every raw coordinate can be wasteful. noted a public service was available; that is one route, but for production use consider rate limits, costs, and terms of use.

Practical workflow that works well in PHP:

  • Deduplicate before calling an API: round coordinates to 4–5 decimals (0.0001° ≈ 11 m) or use geohashes to group nearby points.
  • Cache the API result keyed by the rounded coordinate or geohash. This converts many noisy GPS points into a single address lookup.
  • For large datasets, run a batched/background job and store the formatted address and address components in columns (street, city, postal) so you can query without re-calling the geocoder.
  • Respect provider rules: public Nominatim endpoints require a proper User-Agent/email and rate-limiting; commercial APIs require keys and may have usage limits and billing.

Example PHP skeleton (caching + Nominatim; replace email/User-Agent and obey rate limits):

function reverseGeocode($lat, $lon) {
  $latr = round((float)$lat, 5);
  $lonr = round((float)$lon, 5);
  $cache = __DIR__ . "/cache/{$latr}_{$lonr}.json";
  if (file_exists($cache)) return json_decode(file_get_contents($cache), true);
  $url = "https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat={$latr}&lon={$lonr}&addressdetails=1&email=you@example.com";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_USERAGENT, 'AppName/1.0 (you@example.com)');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $res = curl_exec($ch); curl_close($ch);
  if ($res) file_put_contents($cache, $res);
  return $res ? json_decode($res, true) : null;
}

See Nominatim usage and reverse API details for requirements and limits: Nominatim reverse API and consider the Google Geocoding API for a commercial option: Google Geocoding API overview.

Recommended Answers

All 5 Replies

I've not yet come across this kind of service. This would be very cumbersome, because a lot of coordinates would point to the same address.

Hey,

Thanks a lot. I got the solution.....

I've not yet come across this kind of service. This would be very cumbersome, because a lot of coordinates would point to the same address.

Please share.

Hey,

Thanks a lot. I got the solution.....

If u got the solution i suggest u to mark the thread as solved and also share ur findings with others that may need help with same issue..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.