当前位置: 网学 > 编程文档 > Android > 正文

Android GPS获取地理位置

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: myeducs.cn 发布时间: 13/03/17

【网学网提醒】:网学会员为需要朋友们搜集整理了Android GPS获取地理位置相关资料,希望对各位网友有所帮助!


    AndroidGPS获取地理位置
    importandroid.app.Activity;1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.e);18.19.20.21.22.23.24.25.26.27.28.;29.30.31.32.33.{34.35.36.publicvoidonLocationChanged(Locationlocation){updateWithNewLocation(location);}}privatefinalLocationListenerlocationListener=newLocationListener()updateWithNewLocation(location);locationManager.requestLocationUpdates(provider,2000,10,locationListener);Locationlocation=locationManager.getLastKnownLocation(provider)Criteriacriteria=newCriteria();criteria.setAccuracy(Criteria.ACCURACY_FINE);criteria.setAltitudeRequired(false);criteria.setBearingRequired(false);criteria.setCostAllowed(true);criteria.setPowerRequirement(Criteria.POWER_LOW);Stringprovider=locationManager.getBestProvider(criteria,true);//Stringprovider=LocationManager.GPS_PROVIDER;publicclassCurrentLocationextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);LocationManagerlocationManager;StringserviceName=Context.LOCATION_SERVICE;locationManager=(LocationManager)getSystemService(serviceNamimportandroid.content.Context;importandroid.location.Criteria;importandroid.location.Location;importandroid.location.LocationListener;importandroid.location.LocationManager;importandroid.os.Bundle;importandroid.widget.TextView;
     37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.}}};
    publicvoidonProviderDisabled(Stringprovider){updateWithNewLocation(null);}publicvoidonProviderEnabled(Stringprovider){}publicvoidonStatusChanged(Stringprovider,intstatus,Bundleextras){}privatevoidupdateWithNewLocation(Locationlocation){StringlatLongString;TextViewmyLocationText;myLocationText=(TextView)findViewById(R.id.myLocationText);if(location!=null){doublelat=location.getLatitude();doublelng=location.getLongitude();latLongString="纬度:"+lat+"\n经度:"+lng;}else{latLongString="无法获取地理信息";}myLocationText.setText("您当前的位置是:\n"+latLongString);
    
    
  • 下一篇资讯: android context
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号