gpt4 book ai didi

java - 在android中请求最近的城市

转载 作者:行者123 更新时间:2023-12-02 07:01:41 27 4
gpt4 key购买 nike

我需要仅使用网络提供商来计算 Android 应用程序中的附近城市。我设法使用以下代码来完成此操作,但它使应用程序变得非常慢,并且仅有时有效。



public Locator(final Context c) {

LocationManager locationManager = (LocationManager) c.getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Geocoder gcd = new Geocoder(c, Locale.getDefault());
List addresses;
try {
addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0) {
if(addresses.get(0).getLocality()!=null){
Locator.setCity(addresses.get(0).getLocality());
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}

有什么想法吗?

提前致谢。

最佳答案

您可以尝试Google Place API 。这是example & tutorial

关于java - 在android中请求最近的城市,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16593442/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com