android 卫星gps 获取地址问题
代码如下:
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文件什么的。大家有没知道的?还是怎么解决?