欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android通過gps獲取定位的位置數(shù)據(jù)和gps經(jīng)緯度    

 更新時(shí)間:2014年01月11日 14:18:17   作者:  
這篇文章主要介紹了android通過gps獲取定位的位置數(shù)據(jù)示例,大家參考使用吧

復(fù)制代碼 代碼如下:

package com.action.android_test;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
private Location location=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//獲得位置服務(wù)的名稱
String serviceName = this.LOCATION_SERVICE;
//獲得位置服務(wù)的管理對象
LocationManager locationManager = (LocationManager)getSystemService(serviceName);
// 通過GPS獲取定位的位置數(shù)據(jù)
location = locationManager.getLastKnownLocation(locationManager.GPS_PROVIDER);
updateToNewLocation(location);

    /**服務(wù)管理對象的監(jiān)聽器*/
    //參數(shù)1:定位的方式   參數(shù)2:監(jiān)聽更新間隔時(shí)間(ms)  參數(shù)3:監(jiān)聽更新的距離(m) 參數(shù)4:監(jiān)聽的方法
    locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 2000, 10, new LocationListener() {

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
        public void onProviderEnabled(String provider) {
        }
        public void onProviderDisabled(String provider) {
        }
        public void onLocationChanged(Location location) {
            updateToNewLocation(location);
        }
    });
}
private void updateToNewLocation(Location location) {

    TextView tv1;
    tv1 = (TextView) this.findViewById(R.id.tv1);
    if (location != null) {
        double  latitude = location.getLatitude();
        double longitude= location.getLongitude();
        tv1.setText("經(jīng)緯度為:n"+"維度:" +  latitude+ "n經(jīng)度" + longitude);
    } else {
        tv1.setText("無法獲取地理信息");
    }

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

相關(guān)文章

最新評論