设为首页 加入收藏

TOP

android studio高德地图的显示于定位(附带逆地理编码围栏)(二)
2017-10-12 10:04:01 】 浏览:8541
Tags:android studio 高德 地图 显示 定位 附带 地理 编码 围栏
private AMapLocationClient locationClient = null; private AMapLocationClientOption locationOption = null; private TextView textView; private String[] strMsg; private com.amap.api.maps.AMap aMap; private MapView mapView; private GeocodeSearch geocoderSearch; private Marker geoMarker; private static LatLonPoint latLonPoint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = (TextView)findViewById(R.id.text1); textView = (TextView)findViewById(R.id.textView2); button=(Button)findViewById(R.id.button); mapView = (MapView) findViewById(R.id.map); mapView.onCreate(savedInstanceState);// 此方法必须重写 Location(); final Intent intent=new Intent(); intent.setAction("Utils"); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle data =new Bundle(); data.putString("msg","签到成功"); intent.putExtra("data",data); sendBroadcast(intent); } }); } private void initMap(){ if (aMap == null) { aMap = mapView.getMap(); //用高德默认图标 geoMarker= aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))); //自定义图标 //geoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f) // .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.punch_dw)))); } geocoderSearch = new GeocodeSearch(this); geocoderSearch.setOnGeocodeSearchListener(this); getAddress(latLonPoint); } @Override public void onLocationChanged(AMapLocation loc) { if (null != loc) { Message msg = mHandler.obtainMessage(); msg.obj = loc; msg.what = Utils.MSG_LOCATION_FINISH; mHandler.sendMessage(msg); } } Handler mHandler = new Handler() { public void dispatchMessage(android.os.Message msg) { switch (msg.what) { //定位完成 case Utils.MSG_LOCATION_FINISH: String result = ""; try { AMapLocation loc = (AMapLocation) msg.obj; result = Utils.getLocationStr(loc, 1); strMsg = result.split(","); Toast.makeText(MainActivity.this, "定位成功", Toast.LENGTH_LONG).show(); textView.setText("地址:" + strMsg[0] + "\n" + "经 度:" + strMsg[1] + "\n" + "纬 度:" + strMsg[2]+"\n"); latLonPoint= new LatLonPoint(Double.valueOf(strMsg[2]), Double.valueOf(strMsg[1])); initMap(); } catch (Exception e) { Toast.makeText(MainActivity.this, "定位失败", Toast.LENGTH_LONG).show(); } break; default: break; } }; }; public void Location() { // TODO Auto-generated method stub try { locationClient = new AMapLocationClient(this); locationOption = new AMapLocationClientOption(); // 设置定位模式为低功耗模式 locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); // 设置定位监听 locationClient.setLocationListener(this); locationOption.setOnceLocation(true);//设置为单次定位 locationClient.setLocationOption(locationOption);// 设置定位参数 // 启动定位 locationClient.startLocation(); mHandler.sendEmptyMessage(Utils.MSG_LOCATION_START); } catch (Exception e) { Toast.makeText(MainActivity.this, "定位失败", Toast.LENGTH_LONG)
首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇svn基本常见操作设置 下一篇svn基本常见操作设置

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目