如何编写一个LBS应用
1、设置
在OPhone OS上使用位置服务,首先需要在”设置”->”我的位置”里选中GPS或A-GPS (A-GPS需要GPRS网络连接)。

如果没有打开设置,应用程序会受到下面的回调,可以按参考代码实现。
public void onProviderDisabled(String provider)
{
Log.i(TAG, "listener onProviderDisabled");
/*
* 弹出对话框,提示用户当前GPS/A-GPS没有使能
*/
AlertDialog dialog = new AlertDialog.Builder(GpsAPITest.this)
.setTitle("Provider " + provider + " is disabled...")
.setMessage("In order to use this tool, you need to turn on the provider " + provider +
" Receiver of your device.\n\n" + "Click Ok to go to the system-settings, or Cancel to leave.\n\n" +
"After that please restart this tool")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/*
* 转到设置界面
*/
Intent fireAlarm = new Intent("android.settings.LOCATION_SOURCE_SETTINGS");
fireAlarm.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(fireAlarm);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
})
.create();
dialog.show();
}
{
Log.i(TAG, "listener onProviderDisabled");
/*
* 弹出对话框,提示用户当前GPS/A-GPS没有使能
*/
AlertDialog dialog = new AlertDialog.Builder(GpsAPITest.this)
.setTitle("Provider " + provider + " is disabled...")
.setMessage("In order to use this tool, you need to turn on the provider " + provider +
" Receiver of your device.\n\n" + "Click Ok to go to the system-settings, or Cancel to leave.\n\n" +
"After that please restart this tool")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/*
* 转到设置界面
*/
Intent fireAlarm = new Intent("android.settings.LOCATION_SOURCE_SETTINGS");
fireAlarm.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(fireAlarm);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
})
.create();
dialog.show();
}