1.跑了一下高德提供的POI的源码,感觉还是比较简单的,没有达到想要的效果,还有改进的空间,后面会继续更新。
2.下面直接上代码,已经注释好了
main.java
package com.dragon.arnav.basicFuction.poi;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.NaviPara;
import com.amap.api.maps.model.Poi;
import com.dragon.arnav.R;
/**
* This file created by dragon on 2016/7/19 15:15,belong to com.dragon.arnav.basicFuction.poi .
*/
public class PoiClick extends Activity implements AMap.OnPOIClickListener,AMap.OnMarkerClickListener {
private MapView mMapView;
private AMap mAMap;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.poiclick);
mMapView = (MapView) findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mAMap = mMapView.getMap();
mAMap.setOnPOIClickListener(this);
mAMap.setOnMarkerClickListener(this);
}
@Override
public void onPOIClick(Poi poi){
mAMap.clear();
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(poi.getCoordinate());
TextView textView = new TextView(getApplicationContext());
textView.setText("到"+poi.getName()+"去");
textView.setGravity(Gravity.CENTER);
textView.setTextColor(Color.BLACK);
textView.setBackgroundResource(R.drawable.custom_info_bubble);
markerOptions.icon(BitmapDescriptorFactory.fromView(textView));
mAMap.addMarker(markerOptions);
}
@Override
public boolean onMarkerClick(Marker marker){
NaviPara naviPara = new NaviPara();
naviPara.setTargetPoint(marker.getPosition());
naviPara.setNaviStyle(AMapUtils.DRIVING_AVOID_CONGESTION);
try{
AMapUtils.openAMapNavi(naviPara,getApplicationContext());
} catch (com.amap.api.maps.AMapException e){
AMapUtils.getLatestAMapApp(getApplicationContext());
}
mAMap.clear();
return false;
}
@Override
protected void onResume(){
super.onResume();
mMapView.onResume();
}
@Override
protected void onPause(){
super.onPause();
mMapView.onPause();
}
@Override
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
@Override
protected void onDestroy(){
super.onDestroy();
mMapView.onDestroy();
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<com.amap.api.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.amap.api.maps.MapView>
3.注意添相应的权限,下面是效果图。
![这里写图片描述](https://img-blog.csdn.net/20160719164310074)
![这里写图片描述](https://img-blog.csdn.net/20160719164324372)
![这里写图片描述](https://img-blog.csdn.net/20160719164335262)