android 卫星gps 获取地址问题

Take_all Take_all 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
package com.gpstest;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class GpsTest extends Activity {
OnClickListener listener1 = null;
LocationListener locationlistener =null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationUpdate(locationManager);
//按钮接受事件
final Button gpsButton = (Button)findViewById(R.id.butt);
gpsButton.setOnClickListener(listener1);
listener1 = new OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
LoadCoords(locationManager);
}



};

}

private void LocationUpdate(LocationManager locationManager) {
// TODO Auto-generated method stub
locationlistener= new LocationListener(){

@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if(location != null){
Log.e("SupperMap", "Location changed : Lat:"+location.getLatitude()+"Lng:"+location.getLongitude());

}else{
Log.e("faild", "没有卫星地址!!");

}
}

@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub

}

};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationlistener);
}
private void LoadCoords(LocationManager locationManager) {
// TODO Auto-generated method stub
TextView latText = (TextView) findViewById(R.id.Latitude);
TextView lngText = (TextView) findViewById(R.id.Langitude);
Location location = locationManager.getLastKnownLocation("gps");
if(null == location){
setTitle("定位信息失败");

}else{
latText.setText(Double.toString(location.getLatitude()));
lngText.setText(Double.toString(location.getLongitude()));
}
}
}

可是却获取不到一直都是“定位信息失败”。,到底是哪里出问题,
后来我看了下,好像又要需要导入什么KML文件什么的。大家有没知道的?还是怎么解决?
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
Take_all
Android 80,490 成员 91,375 内容