国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Android 獲取GPS定位信息

AndroidManifest.xml   增加 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

public class ditu extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LocationManager locationManager;
        String serviceName=Context.LOCATION_SERVICE;
        locationManager=(LocationManager)this.getSystemService(serviceName);
        //查詢條件
        Criteria criteria=new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
       
        String provider=locationManager.getBestProvider(criteria,true);
        Location location=locationManager.getLastKnownLocation(provider);
        updateWithNewLocation(location);
        //設(shè)置監(jiān)聽器,自動更新的最小時(shí)間為間隔1秒,最小位移變化超過5米
        locationManager.requestLocationUpdates(provider, 1000, 5, locationListener);
       
    }
private final LocationListener locationListener=new LocationListener(){

   public void onLocationChanged(Location location) {
    updateWithNewLocation(location);
   }

   public void onProviderDisabled(String provider) {
    updateWithNewLocation(null);
   }

   public void onProviderEnabled(String provider) {
   }
   public void onStatusChanged(String provider, int status, Bundle extras) {
   }
  
};
    private void updateWithNewLocation(Location location){
    String latLongString;
    TextView myLocationText;
    myLocationText=(TextView)this.findViewById(R.id.myLocationText);
    if(location!=null){
       double lat=location.getLatitude();
       double lng=location.getLongitude();
       latLongString="維度:"+lat+"\n經(jīng)度"+lng;
    }else{
       latLongString="無法獲取地理信息";
    }
    myLocationText.setText("您所在位置為:"+latLongString);
    }
}

哈哈,只要手機(jī)開了GPS,你就能隨時(shí)定位自己的位置,可惜顯示出來的是經(jīng)緯度,如果結(jié)合google API,那就能顯示在地圖上了。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Android 打開 GPS 導(dǎo)航并獲取位置信息 - 創(chuàng)世軟件團(tuán)隊(duì) - 博客園
Android Location在GPS中的應(yīng)用(一)
Android GPS定位 獲取經(jīng)緯度
android中模擬器中實(shí)現(xiàn)GPS坐標(biāo)改變
android定位和地圖開發(fā)實(shí)例
Android 手機(jī)app三種方法獲取定位地址(自帶API,外接SDK,獲取外網(wǎng)IP)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服