Android 同时使用GPS摄像机和网络提供商
在我的应用程序中,我想让用户知道他的定位…但我想实现GPS和网络提供商…因为GPS提供商并不总是可用…我使用模拟器,我不知道我的代码是否有效 这是我的代码源:(提前感谢) 这是myLocationlistener类:Android 同时使用GPS摄像机和网络提供商,android,networking,gps,provider,Android,Networking,Gps,Provider,在我的应用程序中,我想让用户知道他的定位…但我想实现GPS和网络提供商…因为GPS提供商并不总是可用…我使用模拟器,我不知道我的代码是否有效 这是我的代码源:(提前感谢) 这是myLocationlistener类: public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
Log.i("location", "lat :"+loc.getLatitude());
mylat=loc.getLatitude();
mylong=loc.getLongitude();
for(int i=0; i<results.size(); i++)
{
gare g=results.get(i);
}
list.invalidateViews();
}
@Override
public void onProviderDisabled(String provider)
{
AlertDialog alertDialog = new AlertDialog.Builder(liste_activity.this).create();
alertDialog.setTitle("Le GPS est désactivé");
alertDialog.setMessage(" activez le GPS");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
} });
alertDialog.show();
}
@Override
public void onProviderEnabled(String provider)
{
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
公共类MyLocationListener实现LocationListener
{
@凌驾
位置更改后的公共无效(位置loc)
{
Log.i(“位置”,“纬度:”+loc.getLatitude());
mylat=loc.getLatitude();
mylong=loc.getLongitude();
for(int i=0;i对我来说很好。我通常将我的#requestLocationUpdates()包装在条件中,首先检查可用性
if (this.mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
this.mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
if (this.mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
this.mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
if (this.mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
this.mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
if (this.mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
this.mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}