English 中文(简体)
摘自SDK的LastKnownLocation
原标题:Getting null from getLastKnownLocation on SDK
  • 时间:2009-12-16 18:12:28
  •  标签:
  • android

我与安普森号的位置有关。

我尝试了以下法典:

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location loc = getLastKnownLocation(LocationManager.GPS_PROVIDER);

什么是错的?

最佳回答

在您的<代码>AndroidManifest.xml文档中,您是否登记了一位现场听众?

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location loc = getLastKnownLocation(LocationManager.GPS_PROVIDER);
lm.requestLocationUpdates(LocationManager.GPS, 100, 1, locationListener); 

然后有完成您任务的方法,即<代码>。

private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
    latitude = location.getLatitude();
    longitude = location.getLongitude();
}
问题回答

如果你重新在投稿人中操作该代码,任何要求进入全球定位系统地点的要求将告无效,直到你明确更新该地点(通过,Eclipse

我的问题与你一样,我总是收到一片废地物体,但最后是容易解决。 您必须有一个有效的全球定位系统定位,因此,如果全球定位系统无法运行,而且你有足够的信号,定位物体将等于ALWAYS。

您是否在安妮斯·曼尼费斯颁发许可证? 您需要这些许可才能进入用户地点申请:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

这里,你可以使用:

LocationManager lm = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = lm.getBestProvider(criteria, false);
Location loc = lm.getLastKnownLocation(bestProvider);

last_lat = loc.getLatitude();
last_lng = loc.getLongitude();

你们需要ParaManger这样的案例:

初审:

   LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

Wrong:

Location loc = getLastKnownLocation(LocationManager.GPS_PROVIDER);

更正:

Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签