Я пытаюсь создать приложение, которое будет отображать макет местоположения. Но как только я нажимаю кнопку, чтобы отобразить местоположение, я получаю исключение, что приложение неожиданно остановилось. Вот код:
public class AndroidLBS extends Activity {
public static TextView latText;
public static TextView lngText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button gpsButton = (Button) findViewById(R.id.gpsButton);
gpsButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
LoadCoords();}
});
}
public void LoadCoords()
{
latText = (TextView) findViewById(R.id.latText);
lngText = (TextView) findViewById(R.id.lngText);
Intent in=new Intent("LOC_OBTAINED");
PendingIntent pi=PendingIntent.getBroadcast(this,0,in,0);
registerReceiver(new BroadcastReceiver(){
public void onReceive(Context arg0, Intent arg1)
{
Bundle bundle=arg1.getExtras();
Location loc=(Location)bundle.get(LocationManager.KEY_LOCATION_CHANGED);
Double lat=loc.getLatitude();
Double longitude=loc.getLongitude();
latText.setText(lat.toString());
lngText.setText(longitude.toString());
}
},new IntentFilter("LOC_OBTAINED"));
LocationManager myManager=LocationManager)getSystemService(Context.LOCATION_SERVICE);
myManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER,true);
Location loc=new Location(LocationManager.GPS_PROVIDER);
loc.setLatitude(12.9);
loc.setLongitude(72.9);
myManager.setTestProviderLocation(LocationManager.GPS_PROVIDER,loc);
myManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, pi);
}
}
Может ли кто-нибудь помочь мне с этим? Заранее спасибо!