Android use high moral map

1, custom Marker, main classes BitmapDescriptor 

BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromView(view);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);

2, add more Marker, need to turn the child thread, the new Handler need to give the child thread Looper

Can learn from the high moral map of Demo, address: https://github.com/amap-demo/android-cluster-marker

 

3, set the map's style:

    private void setMapCustomStyleFile() {
       new Thread(new Runnable() {
           @Override
           public void run() {
               InputStream inputStream = null;
               CustomMapStyleOptions mapStyleOptions = new CustomMapStyleOptions();
               try {
                   inputStream = getBaseActivity().getAssets().open("style.data");
                   byte[] b = new byte[inputStream.available()];
                   inputStream.read(b);
                   if (mapStyleOptions != null) {
                       // 设置自定义样式
                       mapStyleOptions.setEnable(true);
                       mapStyleOptions.setStyleData(b);
                       aMap.setCustomMapStyle(mapStyleOptions);
                   }
               } catch (IOException e) {
                   e.printStackTrace();
               } finally {
                   try {
                       if (inputStream != null) {
                           inputStream.close();
                       }
                   } catch (IOException e) {
                       e.printStackTrace();
                   }
               } 
           }
       }).start();
    }

4, high moral map confuse write incomplete, if you need to use a list of cities, you need to have to add red lines:

#3D 地图 V5.0.0之前:
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.amap.mapcore.*{*;}
-keep class com.amap.api.trace.**{*;}
#3D 地图 V5.0.0之后:
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.**{*;}
-keep class com.amap.api.trace.**{*;}
#定位
-keep class com.amap.api.location.**{*;}
-keep class com.amap.api.fence.**{*;}
-keep class com.autonavi.aps.amapapi.model.**{*;}
#搜索
-keep class com.amap.api.services.**{*;}
-keep class com.amap.poisearch.util.**{*;}#额外加上的
#2D地图
-keep class com.amap.api.maps2d.**{*;}
-keep class com.amap.api.mapcore2d.**{*;}
#导航
-keep class com.amap.api.navi.**{*;}
-keep class com.autonavi.**{*;}

-keep class com.app.main.framework.entity.**{*;}
-keep class com.cq.xiangwan.entity.**{*;}
-keep class com.cjt2325.cameralibrary.**{*;}

5, to set the level Marker displays

MarkerOptions.zIndex(float z); 或者 Marker.setZIndex(float z);z值越大就越高,如果需要将Marker最靠近视角显示在最上面,只需要给每个marker设置它的纬度的负数即可。

6. If you need to display an animation Marker, gif similar effect, it currently seems only to set collection of images, but this phone a bit much, poor mobile phone every minute to hang feeling, if only with two pictures feel barely look

marker.setIcons(list); 

7, reverse geocoding

Get information about the city, location by latitude and longitude. LatLonPoint (Double Latitude, longitude Double)

package com.amap.map3d.demo.geocoder;

/**
 * 地理编码与逆地理编码功能介绍
 */
public class ReGeocoderActivity extends Activity implements
		OnGeocodeSearchListener {
 
	private GeocodeSearch geocoderSearch;
	private LatLonPoint latLonPoint = new LatLonPoint(39.90865, 116.39751);
	private Marker regeoMarker;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.geocoder_activity);
		geocoderSearch = new GeocodeSearch(this);
		geocoderSearch.setOnGeocodeSearchListener(this);
        getAddress(latLonPoint);
	}

	/**
	 * 响应逆地理编码
	 */
	public void getAddress(final LatLonPoint latLonPoint) {
		RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200, GeocodeSearch.AMAP);// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
		geocoderSearch.getFromLocationAsyn(query);// 设置异步逆地理编码请求
	}

	/**
	 * 地理编码查询回调
	 */
	@Override
	public void onGeocodeSearched(GeocodeResult result, int rCode) {
	}

	/**
	 * 逆地理编码回调
	 */
	@Override
	public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
		dismissDialog();
		if (rCode == AMapException.CODE_AMAP_SUCCESS) {
			if (result != null && result.getRegeocodeAddress() != null
					&& result.getRegeocodeAddress().getFormatAddress() != null) {
				addressName = result.getRegeocodeAddress().getFormatAddress()
						+ "附近";
				aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
						AMapUtil.convertToLatLng(latLonPoint), 15));
				regeoMarker.setPosition(AMapUtil.convertToLatLng(latLonPoint));
				ToastUtil.show(ReGeocoderActivity.this, addressName);
			} else {
				ToastUtil.show(ReGeocoderActivity.this, R.string.no_result);
			}
		} else {
			ToastUtil.showerror(this, rCode);
		}
	}

}

8, geocoding

package com.amap.map3d.demo.geocoder;
/**
 * 地理编码与逆地理编码功能介绍
 */
public class GeocoderActivity extends Activity implements
		OnGeocodeSearchListener, OnClickListener {
	private ProgressDialog progDialog = null;
	private GeocodeSearch geocoderSearch;
	private String addressName;
	private AMap aMap;
	private MapView mapView;
	private Marker geoMarker;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.geocoder_activity);
        geocoderSearch = new GeocodeSearch(this);
		geocoderSearch.setOnGeocodeSearchListener(this);
        getLatlon("北京市朝阳区方恒国际中心A座");
	}

	/**
	 * 响应地理编码
	 */
	public void getLatlon(final String name) {
		
		GeocodeQuery query = new GeocodeQuery(name, "010");// 第一个参数表示地址,第二个参数表示查询城市,中文或者中文全拼,citycode、adcode,
		geocoderSearch.getFromLocationNameAsyn(query);// 设置同步地理编码请求
	}

	/**
	 * 地理编码查询回调
	 */
	@Override
	public void onGeocodeSearched(GeocodeResult result, int rCode) {
		dismissDialog();
		if (rCode == AMapException.CODE_AMAP_SUCCESS) {
			if (result != null && result.getGeocodeAddressList() != null
					&& result.getGeocodeAddressList().size() > 0) {
				GeocodeAddress address = result.getGeocodeAddressList().get(0);

				if(address != null) {
					aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
							AMapUtil.convertToLatLng(address.getLatLonPoint()), 15));
					geoMarker.setPosition(AMapUtil.convertToLatLng(address
							.getLatLonPoint()));
					addressName = "经纬度值:" + address.getLatLonPoint() + "\n位置描述:"
							+ address.getFormatAddress();
					ToastUtil.show(GeocoderActivity.this, addressName);
				}
			} else {
				ToastUtil.show(GeocoderActivity.this, R.string.no_result);
			}
		} else {
			ToastUtil.showerror(this, rCode);
		}
	}

	/**
	 * 逆地理编码回调
	 */
	@Override
	public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
		
	}

}

 

Published 49 original articles · won praise 2 · Views 8605

Guess you like

Origin blog.csdn.net/yangjunjin/article/details/102806414