2012-12-27 74 views
0

我试图使用GPS提供商获取当前位置。GPS提供商返回空值

  • 但据我所知它工作不正常。在网络提供商的情况下,它返回塔值,不完全是卫星值。
  • 在这里,我附上了一些与GPS提供商相关的代码示例。

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f,this); 

public void onLocationChanged(Location location) { 
    if (location != null) { 
     double lat = location.getLatitude(); 
     double lng = location.getLongitude(); 
     String currentLocation = "Lat: " + lat + " Lng: " + lng; 
     txted.setText(currentLocation); 
     p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000); 
     mc.animateTo(p); 
    } 
} 

public void onProviderDisabled(String provider) { 
    // required for interface, not used 
} 

public void onProviderEnabled(String provider) { 
    // required for interface, not used 
} 

public void onStatusChanged(String provider, int status, Bundle extras) { 
    // required for interface, not used 
} 

回答

0

确保 “使用GPS卫星” 已启用, 从设置开始 - >位置和安全 - >使用GPS卫星。

+0

它已经在On State –

0

试试这个

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,this); 

后你会得到更新按照您的要求。

+0

我也尝试过这种方法,但它没有显示 –

+0

请发布您的完整活动 – nayab