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

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

问题描述

我会如何获取城市的名字在谷歌地图,如果我有一个城市或地区的纬度和经度坐标?

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.

推荐答案

从<一个href="http://developer.android.com/reference/android/location/Geo$c$cr.html"><$c$c>Geo$c$cr对象,你可以调用<一href="http://developer.android.com/reference/android/location/Geo$c$cr.html#getFromLocation%28double,%20double,%20int%29"><$c$c>getFromLocation(double,双,INT) 方法。它会返回 地址 名单具有方法<一个对象href="http://developer.android.com/reference/android/location/Address.html#getLocality%28%29"><$c$c>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());

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

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