GPS获取当前的经度和纬度
2012-06-02 13:47
183 查看
package com.cn.gps;
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.widget.TextView;
public class GpsActivity extends Activity {
/** Called when the activity is first created. */
private TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
text = (TextView)findViewById(R.id.tv1);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
showLocation(location);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, new LocationListener(){
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
showLocation(location);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
showLocation(null);
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
showLocation(locationManager.getLastKnownLocation(provider));
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
});
}
public void showLocation(Location currentLocation){
if(currentLocation != null){
String s = "";
s += "当前位置: (";
s += currentLocation.getLongitude();
s += ",";
s += currentLocation.getLatitude();
s += ")\n 速度: ";
s += currentLocation.getSpeed();
s += "\n 方向: ";
s += currentLocation.getBearing();
s +="\n 高度:";
s += currentLocation.getAltitude();
text.setText(s);
}
else{
text.setText("");
}
}
}
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.widget.TextView;
public class GpsActivity extends Activity {
/** Called when the activity is first created. */
private TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
text = (TextView)findViewById(R.id.tv1);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
showLocation(location);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, new LocationListener(){
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
showLocation(location);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
showLocation(null);
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
showLocation(locationManager.getLastKnownLocation(provider));
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
});
}
public void showLocation(Location currentLocation){
if(currentLocation != null){
String s = "";
s += "当前位置: (";
s += currentLocation.getLongitude();
s += ",";
s += currentLocation.getLatitude();
s += ")\n 速度: ";
s += currentLocation.getSpeed();
s += "\n 方向: ";
s += currentLocation.getBearing();
s +="\n 高度:";
s += currentLocation.getAltitude();
text.setText(s);
}
else{
text.setText("");
}
}
}
相关文章推荐
- Android百度地图——根据城市名,地址名获取GPS纬度、经度值
- iOS. 原生获取当前经度 纬度。 地址
- cesium随笔 — 获取当前鼠标的经度、纬度、高度
- 如何通过GPS获取我当前所在的城市或街道
- 通过 GPS 信息获取当前所在城市名的代码
- Android 获取地理位置的经度和纬度(zz)
- Android Service获取当前位置(GPS+基站)
- 根据地址获取经度和纬度
- Android中通过GPS或NetWork获取当前位置的经纬度
- Android获取当前位置(GPS和网络定位)
- 【总结备用】 Android中通过GPS或NetWork获取当前位置的经纬度
- 获取经度 纬度
- 如何通过GPS获取我当前所在的城市或街道
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
- Android 通过network gps获取当前位置的location信息
- GPS定位纬度,经度后,通过GOOGLE MAP API解析出地址
- HTML5 调用 GPSAPI 获取当前位置的坐标 显示在地图上(有包括百度地图与谷歌地图)
- AndroidGPS获取当前经纬度坐标
- Android 获取地理位置的经度和纬度
- Android编程获取地理位置的经度和纬度实例