如何从谷歌地图中的经纬度坐标获取城市名称? [英] How to get city name from latitude and longitude coordinates in Google Maps?

查看:92
本文介绍了如何从谷歌地图中的经纬度坐标获取城市名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个城镇或地区的经纬度坐标,我如何在 Google 地图中获取城市名称?

How might I obtain the city name in Google Maps if I have latitude and longitude coordinates of a town or area?

我尝试使用纬度、经度并获得国家/地区,但我不知道如何获得城市名称.

I tried using the latitude, longitude and I got country but I don't know how to get city name.

推荐答案

来自 Geocoder 对象,可以调用getFromLocation(double, double, int) 方法.它将返回 Address 对象的列表有一个方法 getLocality().

Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(lat, lng, 1);
if (addresses.size() > 0) {
    System.out.println(addresses.get(0).getLocality());
}
else {
   // do your stuff
}

这篇关于如何从谷歌地图中的经纬度坐标获取城市名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆