基于位置的android应用 Location LocationManager
来源:互联网 发布:macbook装windows 编辑:程序博客网 时间:2024/05/17 20:31
基于位置的android应用 Location LocationManager
package com.javacodegeeks.android.lbs;import android.app.Activity;import android.content.Context;import android.location.Location;import android.location.LocationListener;import android.location.LocationManager;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class LbsGeocodingActivity extends Activity { private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds protected LocationManager locationManager; protected Button retrieveLocationButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener() ); retrieveLocationButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showCurrentLocation(); } }); } protected void showCurrentLocation() { Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { String message = String.format( "Current Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show(); } } private class MyLocationListener implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude() ); Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show(); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(LbsGeocodingActivity.this, "Provider status changed", Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(LbsGeocodingActivity.this, "Provider disabled by the user. GPS turned off", Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(LbsGeocodingActivity.this, "Provider enabled by the user. GPS turned on", Toast.LENGTH_LONG).show(); } } }
from http://www.oschina.net
- 基于位置的android应用 Location LocationManager
- Location:LocationManager的位置获取
- Pro Android学习笔记(一一六):Location(2):LocationManager的位置获取
- Android 位置管理器(LocationManager)
- android location包---LocationManager简介
- LocationManager的位置获取
- android 学习笔记 位置查询LocationManager的基本用法
- 浅析LocationManager的位置定位
- LBS位置服务都有那些应用? LBS(Location Based Service),中文称为基于位置服务的应用
- android LocationManager的使用
- android mapview结合LocationManager应用
- Android获取手机位置(LocationManager)
- Location---Location服务之LocationManager
- Android 地理位置Location服务之LocationManager,Geocoder详解
- Android 地理位置Location服务之LocationManager,Geocoder详解
- Location服务之LocationManager
- Location服务之LocationManager
- Location服务之LocationManager
- Tomcat下 appBase和docBase的区别
- 网络课程专辑
- 数据智慧工程师——计算机和人类之间的中间人——如何从数据中获取有价值的知识
- 安装sql server 2008,提示要删除SQL Server 2005 Express 工具 怎么解决?
- Java闭包之我见
- 基于位置的android应用 Location LocationManager
- 后台线程下的WinFrom窗体控件操作 Invoke
- 常用SAP术语
- SQLSERVER中的全局变量
- 图像分割 之 分水岭算法
- Android:实现隐藏应用功能(续)
- 编写及调试PL/SQL
- maven 报错找不到Could not find artifact maven-plugins:maven-cobertura-plugin:plugin:1.3
- ListCtrl用法