Android 错误:can';无法从地理编码器获取地址 ConnectionDetector cd=新的ConnectionDetector(Healthcare.this); isInternetPresent=cd.isConnectingToInternet(); 如果(isInternetPresent){ GPSTracker gps=新的GPSTracker(本); Geocoder Geocoder=新的地理编码器(Healthcare.this,Locale.getDefault()); if(gps.canGetLocation()){ 试一试{ latitudecur=gps.getLatitude(); longitudecur=gps.getLongitude(); 对数d(“latlong”,“Lattudecur+Lattudecur+Longtudecur”); 列表地址=geoCoder.getFromLocation(latitudecur,Longtudecur,1); Log.e(“FInalAddress1”和“+address.size()); ##标题## }捕获(NullPointerException e){ //TODO:处理异常 }捕获(数字格式){ //TODO:处理异常 }捕获(IOE异常){ e、 printStackTrace(); } }否则{ } }
我在Log.e(“FInalAddress1”和“+address.size())中编写了上述代码;获取0的address.getsize()。从这段代码中无法获取任何内容,如位置、地址等 我对上述代码有什么问题? 请帮忙Android 错误:can';无法从地理编码器获取地址 ConnectionDetector cd=新的ConnectionDetector(Healthcare.this); isInternetPresent=cd.isConnectingToInternet(); 如果(isInternetPresent){ GPSTracker gps=新的GPSTracker(本); Geocoder Geocoder=新的地理编码器(Healthcare.this,Locale.getDefault()); if(gps.canGetLocation()){ 试一试{ latitudecur=gps.getLatitude(); longitudecur=gps.getLongitude(); 对数d(“latlong”,“Lattudecur+Lattudecur+Longtudecur”); 列表地址=geoCoder.getFromLocation(latitudecur,Longtudecur,1); Log.e(“FInalAddress1”和“+address.size()); ##标题## }捕获(NullPointerException e){ //TODO:处理异常 }捕获(数字格式){ //TODO:处理异常 }捕获(IOE异常){ e、 printStackTrace(); } }否则{ } },android,geocoding,Android,Geocoding,我在Log.e(“FInalAddress1”和“+address.size())中编写了上述代码;获取0的address.getsize()。从这段代码中无法获取任何内容,如位置、地址等 我对上述代码有什么问题? 请帮忙 谢谢如果它不起作用,你可以调用谷歌提供的API ConnectionDetector cd = new ConnectionDetector(Healthcare.this); isInternetPresent = cd.isConnectingToInternet();
谢谢如果它不起作用,你可以调用谷歌提供的API
ConnectionDetector cd = new ConnectionDetector(Healthcare.this);
isInternetPresent = cd.isConnectingToInternet();
if (isInternetPresent) {
GPSTracker gps = new GPSTracker(this);
Geocoder geoCoder = new Geocoder(Healthcare.this, Locale.getDefault());
if (gps.canGetLocation()) {
try {
latitudecur = gps.getLatitude();
longitudecur = gps.getLongitude();
Log.d("latlong",""+latitudecur+longitudecur);
List<Address> address = geoCoder.getFromLocation(latitudecur, longitudecur, 1);
Log.e("FInalAddress1",""+address.size());
## Heading ##
} catch (NullPointerException e) {
// TODO: handle exception
} catch (NumberFormatException e) {
// TODO: handle exception
} catch (IOException e) {
e.printStackTrace();
}
} else {
}
}
JSONObject JSONObject=getJsonResponse(“http://maps.google.com/maps/api/geocode/json?latlng=“+mLatitude+”、“+mLatitude+”&sensor=true”);
if(jsonObject!=null){
试一试{
JSONArray JSONArray=jsonObject.getJSONArray(“结果”);
for(int i=0;i
它需要互联网连接。您是否在清单中输入了互联网权限?latlong
是否打印了值?是的,我在清单中输入了互联网权限,还获得了纬度和经度,并且手机有互联网连接?是的,手机也有互联网连接,这就是我获得纬度和经度的原因,但我知道该解决方案,但我想使用它地理编码
JSONObject jsonObject = getJsonResponse("http://maps.google.com/maps/api/geocode/json?latlng=" + mLatitude + "," + mLogitude + "&sensor=true");
if (jsonObject != null) {
try {
JSONArray jsonArray = jsonObject.getJSONArray("results");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject addressResult = jsonArray.getJSONObject(i);
String formattedAddress = addressResult.getString("formatted_address");
}
} catch (JSONException e) {
e.printStackTrace();
}
}