最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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)文章

最新評論

定兴县| 星子县| 鹤峰县| 石台县| 珠海市| 卓资县| 辰溪县| 娱乐| 隆德县| 保山市| 七台河市| 琼结县| 永清县| 什邡市| 江川县| 宾川县| 榆社县| 黑龙江省| 绥德县| 新巴尔虎左旗| 卫辉市| 开封市| 伊川县| 广丰县| 阳谷县| 驻马店市| 兰溪市| 三明市| 滕州市| 灌云县| 繁昌县| 西丰县| 崇州市| 拜泉县| 玛曲县| 尼木县| 怀化市| 故城县| 江北区| 曲阳县| 岱山县|