高德地图Route:
高德地图Route:
先看效果图,出发地点写死了,就是西直门,本来用GPS功能定位的自己的位置,但是现在在上海,到北京路线倒是有,但是地图刷不出来,自己搞的头昏脑涨,就不弄了,把这两个分成两部分,下面写GPS功能。
首先要实现OnRouteSearchListener这个接口,实现这个接口会有3个方法需要重写。1.onWalkRouteSearched,2.onBusRouteSearched,3.onDriveRouteSearched。
重写这三个方法,重写的方式相同,直接看代码。
package com.test.testdemo;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.overlay.BusRouteOverlay;
import com.amap.api.maps.overlay.DrivingRouteOverlay;
import com.amap.api.maps.overlay.WalkRouteOverlay;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeAddress;
import com.amap.api.services.geocoder.GeocodeQuery;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.GeocodeSearch.OnGeocodeSearchListener;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.route.BusPath;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DrivePath;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.WalkPath;
import com.amap.api.services.route.RouteSearch.BusRouteQuery;
import com.amap.api.services.route.RouteSearch.DriveRouteQuery;
import com.amap.api.services.route.RouteSearch.OnRouteSearchListener;
import com.amap.api.services.route.RouteSearch.WalkRouteQuery;
import com.amap.api.services.route.WalkRouteResult;
public class RouteActivity extends Activity implements OnClickListener,
OnGeocodeSearchListener, OnRouteSearchListener {
private GeocodeSearch geocoderSearch;
private String addressName;
private AMap aMap;
private MapView mapView;
private LatLonPoint latLonPoint = new LatLonPoint(39.90865, 116.39751);
private LatLonPoint startLatLonPoint, endLatLonPoint;
private Marker geoMarker, regeoMarker;// 锚点,在地图上进行绘制的点
Location location;
private Context context;
private EditText editText;
private int routeType = 1;// 1代表公交模式,2代表驾车模式,3代表步行模式
private int busMode = RouteSearch.BusDefault;// 公交默认模式
private int drivingMode = RouteSearch.DrivingDefault;// 驾车默认模式
private int walkMode = RouteSearch.WalkDefault;// 步行默认模式
private BusRouteResult busRouteResult;// 公交模式查询结果
private DriveRouteResult driveRouteResult;// 驾车模式查询结果
private WalkRouteResult walkRouteResult;// 步行模式查询结果
private RouteSearch routeSearch;
private Button drivingButton, walkButton, busButton;
private ImageButton routeSearchImagebtn;
private String strend;
private LocationManager locManager;
private LocationListener listener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.route_layout);
mapView = (MapView) findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);// 此方法必须重写
initView();
}
private void initView() {
routeSearch = new RouteSea