这是我的代码,我似乎无法获得使用NETWORK_PROVIDER时的坐标。 onLocationChange()似乎不会触发。我会感激的帮助。在室内时获得GPS坐标
package com.networkprovider;
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.widget.EditText;
import android.widget.Toast;
public class networkProvider extends Activity {
EditText editText1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText1=(EditText)findViewById(R.id.editText1);
}
@Override
protected void onStart() {
LocationManager locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener listener=new LocationListener() {
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
@Override
public void onProviderEnabled(String arg0) {
}
@Override
public void onProviderDisabled(String arg0) {
}
@Override
public void onLocationChanged(Location location) {
String loc=String.valueOf(location.getLatitude())+","+String.valueOf(location.getLongitude());
Toast.makeText(getApplicationContext(),loc, Toast.LENGTH_LONG).show();
//editText1.setText(loc);
}
};
boolean isEnabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(isEnabled)
{
Toast.makeText(getApplicationContext(),"Enabled", Toast.LENGTH_LONG).show();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener);
}
else
{
Toast.makeText(getApplicationContext(),"Not Enabled!", Toast.LENGTH_LONG).show();
}
super.onStart();
}
}
你的代码有没有问题,只是检查权限位置也适用于互联网 – Dharmendra