package com.autonavi.routedemo;
import java.io.IOException;
import java.util.List;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import com.autonavi.mapapi.GeoPoint;
import com.autonavi.mapapi.MapActivity;
import com.autonavi.mapapi.MapView;
import com.autonavi.mapapi.PoiPagedResult;
import com.autonavi.mapapi.PoiSearch;
import com.autonavi.mapapi.PoiTypeDef;
import com.autonavi.mapapi.Route;
import com.autonavi.mapapi.RouteMessageHandler;
import com.autonavi.mapapi.RouteOverlay;
import com.autonavi.mapapi.MapView.LayoutParams;
import com.autonavi.mapapi.Route.FromAndTo;
/*
* 显示MapView 实现PoiSearch及Route功能
*/
public class Main extends MapActivity implements RouteMessageHandler,
OnGestureListener {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstancedState) {
super.onCreate(savedInstancedState);
setContentView(R.layout.main);
mv = (MapView) this.findViewById(R.id.mapView);
mv.setBuiltInZoomControls(true);
setInitView();
}
private void setInitView() {
calculateRoute = (Button) this.findViewById(R.id.CalculateRoute);
setSearch = (Button) this.findViewById(R.id.setStartAndEnd);
driving = (ImageButton) this.findViewById(R.id.driving);
bus = (ImageButton) this.findViewById(R.id.bus);
walk = (ImageButton) this.findViewById(R.id.walk);
calculateRoute.setOnClickListener(clickListener);
setSearch.setOnClickListener(clickListener);
driving.setOnClickListener(clickListener);
bus.setOnClickListener(clickListener);
bus.setBackgroundResource(R.drawable.transit_down);
walk.setOnClickListener(clickListener);
mv.setLongClickable(true);
mGestureDetector.setIsLongpressEnabled(true);
}
private void showPoiOverlay(String poiType, String cityStr, boolean start) {
try {
if (start) {
// PoiSearch.Query 设置POI 查询条件
// startStr为查询字符串,poiType为类型,cityStr是城市代码
poiSearchStart = new PoiSearch(this, new PoiSearch.Query(
startStr, poiType, cityStr));
// 返回 PoiPagedResult
resultStart = poiSearchStart.searchPOI();
// PoiOverlaySelectPoint继承自PoiOverlay,resultStart.getPage(1),取结果第一页
selectPointStart = new PoiOverlaySelectPoint(null, resultStart
.getPage(1), startPoint, endPoint, true, this);
selectPointStart.addToMap(mv);
} else {
poiSearchEnd = new PoiSearch(this, new PoiSearch.Query(endStr,
poiType, cityStr));
// 返回 PoiPagedResult
resultEnd = poiSearchEnd.searchPOI();
// PoiOverlaySelectPoint继承自PoiOverlay,resultStart.getPage(1),取结果第一页
selectPointEnd = new PoiOverlaySelectPoint(null, resultEnd
.getPage(1), startPoint, endPoint, false, this);
selectPointEnd.addToMap(mv);
}
} catch (IOException e) {
this.showToast("网络连接异常");
e.printStackTrace();
}
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = this.getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.exit: {
// // 调用系统home键退出
// Intent i = new Intent(Intent.ACTION_MAIN);
// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// i.addCategory(Intent.CATEGORY_HOME);
// startActivity(i);
// break;
// 2.1 退出有效
// ActivityManager manager = (ActivityManager) this
// .getSystemService(this.getApplicationContext().ACTIVITY_SERVICE);
// manager.restartPackage(this.getPackageName());
this.finish();
break;
}
case R.id.about: {
new AlertDialog.Builder(Main.this).setMessage(R.string.about)
.create().show();
break;
}
default:
break;
}
return false;
}
private void setModeBackResource(int mode) {
if (mode == Route.DrivingDefault) {
driving.setBackgroundResource(R.drawable.driving_down);
walk.setBackgroundResource(R.drawable.walk);
bus.setBackgroundResource(R.drawable.transit);
} else if (mode == Route.BusDefault) {
bus.setBackgroundResource(R.drawable.transit_down);
walk.setBackgroundResource(R.drawable.walk);
driving.setBackgroundResource(R.drawable.driving);
} else if (mode == Route.WalkDefault) {
walk.setBackgroundResource(R.drawable.walk_down);
bus.setBackgroundResource(R.drawable.transit);
driving.setBackgroundResource(R.drawable.driving);
}
}
OnClickListener clickListener = new OnClickListener() {
public void reCalculate(int mode, GeoPoint start, GeoPoint end) {
setModeBackResource(mode);
if ((startPoint != null) && (endPoint != null)) {
if (oldMode != mode) {
try {
displayRoute(startPoint, endPoint, mode);
} catch (IllegalArgumentException e) {
} catch (Exception e1) {
}
}
}
}
@Override
public void onClick(View v) {
// 计算路径
if (calculateRoute.equals(v)) {
if (selectPointStart != null && selectPointEnd != null) {
startPoint = selectPointStart.getStartPoint();
endPoint = selectPointEnd.getEndPoint();
} else if (selectPointStart == null && selectPointEnd != null) {
endPoint = selectPointEnd.getEndPoint();
} else if (selectPointStart != null && selectPointEnd == null) {
startPoint = selectPointStart.getStartPoint();
}
try {
mv.getOverlays().clear();
displayRoute(startPoint, endPoint, mode);
} catch (IllegalArgumentException e) {
} catch (Exception e1) {
}
setModeBackResource(mode);
}
// POISearch
if (setSearch.equals(v)) {
calculateRoute.setClickable(true);
Intent intent = new Intent(Main.this, SearchInput.class);
Bundle dle = new Bundle();
dle.putString("start", startStr);
dle.putString("end", endStr);
dle.putString("mode", String.valueOf(mode));
intent.putExtras(dle);
if (routeOverlay != null) {
routeOverlay.removeFromMap(mv);
}
Main.this.startActivityForResult(intent, REQUESTCODE);
}
// 自驾模式
if (driving.equals(v)) {
if (modeClick) {
mode = Route.DrivingDefault;
reCalculate(mode, startPoint, endPoint);
}
}
// 公交模式
if (bus.equals(v)) {
if (modeClick) {
mode = Route.BusDefault;
reCalculate(mode, startPoint, endPoint);
}
}
// 步行模式
if (walk.equals(v)) {
if (modeClick) {
mode = Route.WalkDefault;
reCalculate(mode, startPoint, endPoint);
}
}
// MapView 点击选择起点
if (popupDipStart != null && popupDipStart.equals(v)) {
startPoint = tempPoint;
Intent intent = new Intent(Main.this, SearchInput.class);
Bundle dle = new Bundle();
dle.putString("start", POINT_IN_MAP);
dle.putString("end", endStr);
dle.putString("mode", String.valueOf(mode));
intent.putExtras(dle);
mv.removeView(popupDipStart);
Main.this.startActivityForResult(intent, REQUESTCODE);
// MapView 点击选择终点
} else if (popupDipEnd != null && popupDipEnd.equals(v)) {
endPoint = tempPoint;
Intent intent = new Intent(Main.this, SearchInput.class);
Bundle dle = new Bundle();
dle.putString("start", startStr);
dle.putString("end", POINT_IN_MAP);
dle.putString("mode", String.valueOf(mode));
intent.putExtras(dle);
mv.removeView(popupDipEnd);
Main.this.startActivityForResult(intent, REQUESTCODE);
}
}
};
@Ov
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android 导航源码 (132个子文件)
resources.ap_ 217KB
MapApiDemo_Route.apk 470KB
MapApiDemo_Route.apk 470KB
Main.class 15KB
PoiOverlaySelectPoint.class 5KB
Main$1.class 4KB
SearchInput.class 3KB
SearchInput$1.class 3KB
PoiOverlaySelectPoint$1.class 1KB
R$drawable.class 1KB
Main$2.class 961B
R$id.class 838B
R.class 609B
R$string.class 468B
R$layout.class 442B
R$menu.class 393B
R$attr.class 352B
.classpath 355B
Thumbs.db 7KB
classes.dex 202KB
Main.java 16KB
SearchInput.java 4KB
PoiOverlaySelectPoint.java 3KB
R.java 3KB
popup.png 11KB
popup.png 11KB
popup.png 11KB
popup.png 11KB
exit.png 4KB
exit.png 4KB
exit.png 4KB
exit.png 4KB
help.png 4KB
help.png 4KB
help.png 4KB
help.png 4KB
icon.png 3KB
icon.png 3KB
icon.png 3KB
icon.png 3KB
dip.png 3KB
dip.png 3KB
search_1.png 3KB
search_1.png 3KB
calculate_1.png 3KB
calculate_1.png 3KB
calculate_2.png 2KB
calculate_2.png 2KB
walk_down.png 2KB
walk_down.png 2KB
calculate_1.png 2KB
walk.png 2KB
walk.png 2KB
calculate_0.png 2KB
calculate_0.png 2KB
search_1.png 2KB
walk_focused.png 2KB
walk_focused.png 2KB
search_0.png 2KB
search_0.png 2KB
calculate_2.png 2KB
search_2.png 2KB
search_2.png 2KB
driving_down.png 2KB
driving_down.png 2KB
calculate_0.png 2KB
driving.png 2KB
driving.png 2KB
driving_focused.png 2KB
driving_focused.png 2KB
search_0.png 2KB
walk_down.png 2KB
search_2.png 2KB
walk_focused.png 2KB
dip.png 2KB
transit_focused.png 2KB
transit_focused.png 2KB
driving_down.png 2KB
transit_down.png 2KB
walk.png 2KB
transit.png 2KB
transit.png 2KB
driving_focused.png 1KB
calculate_1.png 1KB
search_1.png 1KB
transit_down.png 1KB
transit_down.png 1KB
calculate_2.png 1KB
transit_focused.png 1KB
calculate_0.png 1KB
driving.png 1KB
search_0.png 1KB
walk_focused.png 1KB
transit.png 1KB
walk_down.png 1KB
transit_focused.png 1KB
driving_focused.png 1KB
driving_down.png 1KB
transit_down.png 1KB
search_2.png 1KB
共 132 条
- 1
- 2
lg279908129
- 粉丝: 3
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页