我和其他几个人正在开发一个适用于 android 的应用程序。它需要在纬度和经度上定位设备。我们已经能够创建一个位置对象,但该对象始终是空白的。我们甚至尝试在一个完全空的项目中重新创建代码,但这也失败了。这是我们的根活动:
package com.app.Locationtest;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
public class locationtest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locman =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location loc = locman.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (loc==null)
{
finish();
}
}
}
这是清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.Locationtest"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".locationtest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
我们如何解决这个问题?