基本信息
源码名称:高德地图的gps、wifi、基站的智能选择定位例子源码
源码大小:0.74M
文件格式:.zip
开发语言:Java
更新时间:2016-02-14
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.gu.ALocationByGD; import android.app.Activity; import android.content.Intent; import android.location.Location; import android.os.Bundle; import android.view.View; import com.amap.api.location.AMapLocation; import com.amap.api.location.AMapLocationListener; import com.amap.api.location.LocationManagerProxy; import com.amap.api.location.LocationProviderProxy; /** * 本实例采用高德的智能定位包进行的智能选择定位方式进行定位,wifi网络、周围基站以及gps */ public class MyActivity extends Activity { /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViewById(R.id.location).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //开始定位 initLocation(); } }); } //定位管理服务 private LocationManagerProxy mLocationManagerProxy; //停止定位,在定位完不需要再次定位是关闭定位服务,释放资源 private void stopLocation() { if (mLocationManagerProxy != null) { mLocationManagerProxy.removeUpdates(amapLocationListener); mLocationManagerProxy.destory(); } mLocationManagerProxy = null; } //初始化定位 private void initLocation() { mLocationManagerProxy = LocationManagerProxy.getInstance(this); //此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗, //注意设置合适的定位时间的间隔,并且在合适时间调用removeUpdates()方法来取消定位请求 //在定位结束后,在合适的生命周期调用destroy()方法 //其中如果间隔时间为-1,则定位只定一次 mLocationManagerProxy.requestLocationUpdates(LocationProviderProxy.AMapNetwork, -1, 1, amapLocationListener); mLocationManagerProxy.setGpsEnable(false); } //定位监听 private AMapLocationListener amapLocationListener = new AMapLocationListener() { @Override public void onLocationChanged(AMapLocation aMapLocation) { if (aMapLocation != null) { saveDisconnectLocation(aMapLocation); } } @Override public void onLocationChanged(Location location) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; double lat, lon; //保存定位到的坐标位置,并跳转到地图界面进行定位 private void saveDisconnectLocation(AMapLocation amaplocation) { lon = amaplocation.getLongitude(); lat = amaplocation.getLatitude(); // disconnect record if (lon != 0 && lat != 0) { stopLocation(); Intent intent = new Intent(); intent.setClass(MyActivity.this, MapActivity.class); intent.putExtra("lat", lat); intent.putExtra("lon", lon); startActivity(intent); finish(); } } }