if (0.0 == locateLat || 0.0 == locateLng) {
MyLog.e(“[Location
]Error Location, not update map”);
} else {
isLocated = true;
nowLatLng = new LatLng(locateLat, locateLng);
mListener.onLocationChanged(aLocation); // 显示系统小蓝点
}
MyLog.v(“[Location]Lat:” + locateLat + “,Lng:” + locateLng);
}
}
2.进行POI检索
/**
- 开始进行poi搜索
*/
protected void doSearchQuery() {
showProgressDialog(); // 显示进度框
currentPage = 0; // 重置页码
query = new PoiSearch.Query(keyWord, “”, editCity.getText().toString());// 第一个参数表示搜索字符串,第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代表全国)
query.setPageSize(10); // 设置每页最多返回多少条poiitem
query.setPageNum(currentPage);// 设置查第一页
poiSearch = new PoiSearch(this, query);
poiSearch.setOnPoiSearchListener(this);
poiSearch.searchPOIAsyn();
}
3.设置点击InfoWindow动作:
@Override
public View getInfoWindow(final Marker marker) {
View view = getLayoutInflater().inflate(R.layout.poikeywordsearch_uri,
null);
TextView title = (TextView) view.findViewById(R.id.title);
title.setText(marker.getTitle());
TextView snippet = (TextView) view.findViewById(R.id.snippet);
snippet.setText(marker.getSnippet());
ImageButton button = (ImageButton) view
.findViewById(R.id.start_amap_app);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 导航
// 起点终点列表
ArrayList startPoints = new ArrayList();
ArrayList endPoints = new ArrayList();
LatLng endLatLng = marker.getPosition();
NaviLatLng endNaviLatLng = new NaviLatLng(endLatLng.latitude,
endLatLng.longitude);
endPoints.add(endNaviLatLng);
NaviLatLng startNaviLatLng = new NaviLatLng(nowLatLng.latitude,
nowLatLng.longitude);
startPoints.add(startNaviLatLng);
if (isLocated) {
// DrivingSaveMoney–省钱
// DrivingShortDistance–最短距离
// DrivingNoExpressways–不走高速
// DrivingFastestTime–最短时间
// DrivingAvoidCongestion–避免拥堵
AMapNavi.getInstance(MainActivity.this)
.calculateDriveRoute(startPoints, endPoints, null,
AMapNavi.DrivingDefault);
mRouteCalculatorProgressDialog.show();
} else {
Toast.makeText(getApplicationContext(), “未定位”,
Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
目前起始点之间路径上的箭头是反向的,后面看一下什么原因。
4.Update:添加模拟导航
@Override
public void onCalculateRouteSuccess() {
mRouteCalculatorProgressDialog.dismiss();
Intent intent = new Intent(MainActivity.this, SimpleNaviActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Bundle bundle = new Bundle();
bundle.putInt(AMapUtil.ACTIVITYINDEX, AMapUtil.SIMPLEGPSNAVI);