无法解析符号 'Address' android studio
cannot resolve symbol 'Address' android studio
我正在使用此 link How to find postcode by latitude and logitude for UK and this link Get current location using GPS in Android 获取用户经纬度,然后将其转换为 post 代码。但是,我在地址上收到错误消息,它显示 cannot resolve symbol 'Address' android studio
并且因此 address= geoCoder.getFromLocation(latitude, longitude, 1)
;这 String postCode = address.get(0).getPostalCode();
行。
Geocoder geoCoder = new Geocoder(getActivity().getApplicationContext(), Locale.getDefault());
List<Address> address = null;
if (geoCoder != null){
try {
address= geoCoder.getFromLocation(latitude, longitude, 1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (address.size()> 0){
String postCode = address.get(0).getPostalCode();
}
如果你能帮忙,那就太好了。我是 android 的新手,不知道如何解决这个问题。如果我的问题不清楚,请告诉我。
已编辑:
清单中的前置条件:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Gradel 编译
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v4:23.0.1'
尝试将播放服务更新到最新版本 8.4.0
dependencies {
compile 'com.google.android.gms:play-services:8.4.0'
}
解决了我的问题,原来是要import
import android.location.Address;
我正在使用此 link How to find postcode by latitude and logitude for UK and this link Get current location using GPS in Android 获取用户经纬度,然后将其转换为 post 代码。但是,我在地址上收到错误消息,它显示 cannot resolve symbol 'Address' android studio
并且因此 address= geoCoder.getFromLocation(latitude, longitude, 1)
;这 String postCode = address.get(0).getPostalCode();
行。
Geocoder geoCoder = new Geocoder(getActivity().getApplicationContext(), Locale.getDefault());
List<Address> address = null;
if (geoCoder != null){
try {
address= geoCoder.getFromLocation(latitude, longitude, 1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (address.size()> 0){
String postCode = address.get(0).getPostalCode();
}
如果你能帮忙,那就太好了。我是 android 的新手,不知道如何解决这个问题。如果我的问题不清楚,请告诉我。
已编辑:
清单中的前置条件:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Gradel 编译
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v4:23.0.1'
尝试将播放服务更新到最新版本 8.4.0
dependencies {
compile 'com.google.android.gms:play-services:8.4.0'
}
解决了我的问题,原来是要import
import android.location.Address;