2013-01-16 117 views
1

我有新的華爲手機Ascend G330D,板載4.0.4。 問題是「網絡」位置提供程序不起作用,並且根本不返回任何座標。網絡位置提供商無法在ICS上工作(華爲)

其他事實 1.應用程序是正確─它可以在相當多的Android設備 2. GPS位置提供好的工作 3.谷歌地圖應用,即使網絡位置完美的作品(即沒有全球定位系統)! (我已經取代/ system/app中的NetworkLocation.apk,此後Google應用(Maps,Local)開始使用網絡位置,最初它們都不能工作) 4.沒有任何第三方應用(來自市場)位置以及

由於地圖是不開源的,我看不出這是與應用程序,它使用谷歌API的差別,但我想,谷歌地圖只是可以使用地理位置(或授權密鑰)的另一個來源...

有沒有人有任何想法去挖掘網絡位置工作?

+1

的問題與位置提供者使用無關,但與特定設備(或fw)無關。我的程序工作正常,其他程序(除谷歌的)都不工作。我已經從調試器 - 網絡提供商檢查啓用。 –

回答

0

您可以檢查此教程完整的例子

Get Current Location coordinates , City name

而且,這裏是正在與這兩個

  • GPS提供商
  • 網絡提供商
我的工作代碼

public class MyLocationListener e xtends服務實現LocationListener的{

private static final String TAG = "MyLocationListener"; 

private Context context = null; 

private Location location = null; 
private LocationManager locationManager = null; 

public static boolean isGPSEnabled = false; 
boolean isNetworkEnabled = false; 
boolean canGetLocation = false; 

public double latitude = 0.0; 
public double longitude = 0.0; 
public String location_address = null; 

// The minimum distance to change Updates in meters 
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; 
// The minimum time between updates in milliseconds 
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute 

public MyLocationListener(Context ctx) { 
    Log.v(TAG + ".MyLocationListener", 
      "MyLocationListener constructor called"); 
    this.context = ctx; 
    getLocationValue(); 
} 

public Location getLocationValue() { 
    Log.v(TAG + ".getLocationValue", "getLocationValue method called"); 

    try { 
     locationManager = (LocationManager) context 
       .getSystemService(LOCATION_SERVICE); 

     isGPSEnabled = locationManager 
       .isProviderEnabled(LocationManager.GPS_PROVIDER); 

     isNetworkEnabled = locationManager 
       .isProviderEnabled(LocationManager.NETWORK_PROVIDER); 

     if (isGPSEnabled) { 

      this.canGetLocation = true; 
      Log.v(TAG + ".getLocationValue", "GPS provider enabled"); 
      // Toast.makeText(context, "Gps", 1).show(); 
      if (location == null) { 
       locationManager.requestLocationUpdates(
         LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, 
         MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 
       if (locationManager != null) { 
        location = locationManager 
          .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
        if (location != null) { 
         latitude = location.getLatitude(); 
         longitude = location.getLongitude(); 
         Log.v(TAG, "Gps Co-ordinates are:" + latitude + " " 
           + longitude); 

        } 
       } 
      } 

     } else if (isNetworkEnabled) { 

      // Toast.makeText(context, "Net", 1).show(); 
      Log.v(TAG + ".getLocationValue", "Network provider enabled"); 
      locationManager.requestLocationUpdates(
        LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, 
        MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

      if (locationManager != null) { 
       location = locationManager 
         .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
       if (location != null) { 
        latitude = location.getLatitude(); 
        longitude = location.getLongitude(); 
        Log.v(TAG, "Co-ordinates are: " + latitude + " " 
          + longitude); 

       } 
      } 

     } else { 
      showSettingsAlert(); 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    return location; 
} 

/** 
* Stop using GPS listener Calling this function will stop using GPS in your 
* app 
* */ 
public void stopUsingGPS() { 
    if (locationManager != null) { 
     locationManager.removeUpdates(MyLocationListener.this); 
    } 
} 

public double getLatitude() { 
    if (location != null) { 
     latitude = location.getLatitude(); 
    } 
    return latitude; 
} 

public double getLongitude() { 
    if (location != null) { 
     longitude = location.getLongitude(); 
    } 
    return longitude; 
} 

/** 
* Function to check GPS/wifi enabled 
* 
* @return boolean 
* */ 
public boolean canGetLocation() { 
    return this.canGetLocation; 
} 

/** 
* Function to show settings alert dialog On pressing Settings button will 
* lauch Settings Options 
* */ 
public void showSettingsAlert() { 
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); 

    alertDialog.setTitle("GPS Settings"); 
    alertDialog 
      .setMessage("GPS is not enabled. Do you want to go to settings menu?"); 

    alertDialog.setPositiveButton("Settings", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        Intent intent = new Intent(
          Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
        context.startActivity(intent); 
       } 
      }); 
    alertDialog.setNegativeButton("Cancel", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
       } 
      }); 
    alertDialog.show(); 
} 

@Override 
public void onLocationChanged(Location location) { 
} 

@Override 
public void onProviderDisabled(String provider) { 
} 

@Override 
public void onProviderEnabled(String provider) { 
} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
} 

@Override 
public IBinder onBind(Intent intent) { 
    return null; 
}} 

使用上面的代碼這種方式,只要你在任何活動

MyLocationListener mylistner = new MyLocationListener(context); 
     double lat = mylistner.latitude; 
     double lon = mylistner.longitude; 

注意想:我也有打擊的權限在我的清單

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.INTERNET"/> 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/> 
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> 
相關問題