寻找高德地图机车版图

用高德地图如何快速找到身边的药店、停车场和洗手间
用高德地图如何快速找到身边的药店、停车场和洗手间
寸土寸金的大城市里,洗手间、停车场往往“相当低调”,它们藏在城市隐蔽的角落里,让急用的人们无从找起!对于初来乍到的人来说,走冤枉路、到处打听,一路上满头大汗、颇费周折;而如果遇到半夜身体不舒服,则要心急如焚地像无头苍蝇一样到处寻找药店——生活中这些突发的小状况总会让我们措手不及。
别担心!高德地图为我们考虑了更多!找停车场这种行车导航类技能对于高德地图来说简直是炉火纯青——高德网罗了城市及郊区所有的停车场,哪怕一小块停车位也绝不放过!而找卫生间、药店这种人们在生活中经常遇到的小麻烦,对于高德地图来说也不在话下!高德地图就像一位贴心的“小暖男”——知你所需,急你所急。
停车场信息详实智能 一键导航助您停车无忧
自驾出行,最揪心的不仅仅是堵车,还有找不到停车场的烦恼!据有关数据统计,中国城市对停车位的需求缺口在50%以上,特别是景点、商圈、医院和学校周边等地区尤为严重。寻找停车位这个人人争抢的“香饽饽”,就放心地交给高德地图吧!
▲抵达目的地前会自动向用户推荐目的地附近停车场
当您使用高德地图导航时,在即将抵达目的地前,高德地图会通过语音自动提示您:“已经找到终点附近停车场,是否导航?”同时在手机屏幕上将目的地附近的停车场信息呈现出来。只需点击导航屏幕来选择,高德便会准确地将您导航到选中的停车场。
▲在页面中直接搜索“停车场”,一键导航,即可获取导航路线
此外,高德地图还有专门的停车场选项。只需打开“附近”功能里的“驾车助手”,点击“停车场”,就可以看到您当前所在地附近的所有停车场信息。再点击任意一个心仪的选项,就可以轻松抵达了!
高德地图还有智慧景区服务功能,能够在景区这种人流量大的热门地点为您轻松找到停车位。使用方法也非常简单,只需抵达景区后,放大地图显示景区导览图,点击页面左边的景区筛选按钮,选中“停车场”,高德就能够为您显示景区周边的所有停车场信息了!
找卫生间不再羞答答 高德地图帮你摆脱尴尬
无论是旅游、访友还是逛街购物,都可能遇到急需找卫生间的窘境,这种羞答答的事情对有些面子薄的人来说还挺难以启齿的。这时候只需有高德地图,这样的尴尬瞬间可以被化解。高德地图能快速地找到您所在位置周边所有卫生间信息,一键指引,解决燃眉之需!
▲在页面中直接搜索“卫生间”,一键导航,即可获取导航路线
在搜索栏中输入“卫生间”,高德地图会根据距离长短为您罗列出所有附近的卫生间。同时,您还可以直观地在屏幕上方的地图中看到这些卫生间分布的位置,快速判断一条最便捷的路线。
▲点击“查找”即可显示高德智慧景区服务的分类,点选“卫生间”即可呈现筛选结果
如果身在人头攒动的景区,你也无需满头大汗寻找卫生间。高德地图的智慧景区服务已经为您贴心地考虑到了!在景区导览图中点击左侧查找按钮,选中“洗手间”后,您就安心地跟着地图上的路线走吧!
应急时刻快速定位药店 高德地图为您保驾护航
对于没有随身携带药物的心脏病、哮喘病人来说,当身体突发不适时,快速定位到附近的一家药店往往比大费周章地前往医院更能保命!而如果是小朋友晚上发烧、拉肚子,能否在最短的时间内找到药店则考验着每一位家长的小心脏!
▲在页面中直接搜索“药店”关键词,即可呈现附近所有药店
高德地图网罗了详尽的药店、诊所和医院信息。只需通过 “更多”— “热门”类别中选择“药店”,或是直接在搜索栏中输入“药店”关键词,高德地图便能快速地为您显示附近的大小药店。
▲高德地图提供详细的医院资质、特色科室和著名医师介绍,部分医院可直接挂号
使用相同的方法还可以查询到所在位置附近所有医院的距离、电话等信息,同时还能查看到医院资质、特色科室以及著名医师介绍。此外,高德地图还提供部分医院的“预约挂号”功能,真正做到争分夺秒,节省最宝贵的时间!
大到停车场、医院,小到卫生间、药店,高德地图就像一位全能的“暖男”,能够在最紧急的时刻帮你寻找最重要的目的地,真正做到“知你所需,急你所急”!高德地图——搜索
这里使用的高德搜索SDK为: AMap_Search_V3.30_.jar
地图SDK提供了一系列的接口来方便用户获取高德LBS数据,目前主要支持的检索有:
o 兴趣点搜索:
1. 关键字搜索
2. 周边搜索
3. 指定区域搜索(与关键字搜索相同,这里不再介绍)
4. 团购/优惠搜索(这里不做介绍)
5. POI深度信息(这里不做介绍)
o 输入提示搜索
o 路径规划
o 公交线路查询
o 坐标/地址查询
这里仅仅进行简单的介绍,简单的记录一下学习笔记!
希望对大家能够起到一个抛砖引玉的作用
关键字搜索
搜索条件设置
您需要通过 PoiSearch.Query(String query, String ctgr, String city) 设置搜索条件
参数“ query” 为搜索的关键字,“ ctgr” 为搜索类型(类型参照表从相关下载处获取),“ city”为搜索城市,
关键字、类型至少输入一个,搜索城市必须输入,
通过 Query.setPageSize(int) 设置查询每页的结果数目;
通过 Query.setPageNum(int) 设置查询第几页
发送请求和接收数据
使用 PoiSearch.searchPOIAsyn() 搜索 POI,
使用 PoiSearch.setOnPoiSearchListener()方法设置监听器,
在 PoiSearch.OnPoiSearchListener 接口回调方法
onPoiSearched(PoiResult poiResult,int rCode)中处理返回结果,当指定搜索城市时,若没有返回 POI 结果,则会返回包含关键字的建议城市名称
int currentPage = 0;
query = new PoiSearch.Query("kfc", "餐饮", "北京");
query.setPageSize(10);
query.setPageNum(currentPage);
PoiSearch poiSearch = new PoiSearch(this, query);
poiSearch.setOnPoiSearchListener(this);
poiSearch.searchPOIAsyn();
public void onPoiItemSearched(PoiItem arg0, int arg1) {
public void onPoiSearched(PoiResult result, int rCode) {
if (result != null && result.getQuery() != null) {
if (result.getQuery().equals(query)) {
poiResult =
List&PoiItem& poiItems = poiResult.getPois();
if (poiItems != null && poiItems.size() & 0) {
aMap.clear();
PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems);
poiOverlay.removeFromMap();
poiOverlay.addToMap();
poiOverlay.zoomToSpan();
List&SuggestionCity& suggestionCities = poiResult
.getSearchSuggestionCitys();
完整代码如下:
package com.hang.
import java.util.L
import android.app.A
import android.os.B
import com.amap.api.maps.AM
import com.amap.api.maps.MapV
import com.amap.api.maps.overlay.PoiO
import com.amap.api.services.core.PoiI
import com.amap.api.services.core.SuggestionC
import com.amap.api.services.poisearch.PoiR
import com.amap.api.services.poisearch.PoiS
import com.amap.api.services.poisearch.PoiSearch.Q
public class BasePoiSearchActivity extends Activity implements
PoiSearch.OnPoiSearchListener {
MapView mapV
Query query = null;
PoiResult poiResult = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView=new MapView(this);
setContentView(mapView);
mapView.onCreate(savedInstanceState);
aMap = mapView.getMap();
int currentPage = 0;
query = new PoiSearch.Query("kfc", "餐饮", "北京");
query.setPageSize(10);
query.setPageNum(currentPage);
PoiSearch poiSearch = new PoiSearch(this, query);
poiSearch.setOnPoiSearchListener(this);
poiSearch.searchPOIAsyn();
public void onPoiItemSearched(PoiItem arg0, int arg1) {
public void onPoiSearched(PoiResult result, int rCode) {
if (result != null && result.getQuery() != null) {
if (result.getQuery().equals(query)) {
poiResult =
List&PoiItem& poiItems = poiResult.getPois();
if (poiItems != null && poiItems.size() & 0) {
aMap.clear();
PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems);
poiOverlay.removeFromMap();
poiOverlay.addToMap();
poiOverlay.zoomToSpan();
List&SuggestionCity& suggestionCities = poiResult
.getSearchSuggestionCitys();
protected void onResume() {
super.onResume();
mapView.onResume();
protected void onPause() {
super.onPause();
mapView.onPause();
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
在关键字基础上通过PoiSearch.SearchBound(LatLonPoint center, int
radiusInMeters) 设置周边圆形搜索范围,参数 “ center” 为搜索的中心点坐标,“ radiusInMeters” 为周边搜索的范围
为了更好的演示效果,这里多添加一点东西
package com.hang.helloamap
import java.util.List
import android.app.Activity
import android.graphics.Color
import android.os.Bundle
import com.amap.api.maps.AMap
import com.amap.api.maps.MapView
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CircleOptions
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.PoiOverlay
import com.amap.api.services.core.LatLonPoint
import com.amap.api.services.core.PoiItem
import com.amap.api.services.core.SuggestionCity
import com.amap.api.services.poisearch.PoiResult
import com.amap.api.services.poisearch.PoiSearch
import com.amap.api.services.poisearch.PoiSearch.Query
import com.amap.api.services.poisearch.PoiSearch.SearchBound
import com.pansoft.oilgas.gaodenavigation.R
public class PoiBoundSearchActivity extends Activity implements
PoiSearch.OnPoiSearchListener {
MapView mapView
Query query = null
PoiResult poiResult = null
Marker locationMarker
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
mapView = new MapView(this)
setContentView(mapView)
mapView.onCreate(savedInstanceState)
aMap = mapView.getMap()
int currentPage = 0
// 第一个参数表示搜索字符串,第二个参数表示POI搜索类型二选其一
// 第三个参数表示POI搜索区域的编码,必设
query = new PoiSearch.Query("", "餐厅", "北京")
query.setPageSize(10)
query.setPageNum(currentPage)
PoiSearch poiSearch = new PoiSearch(this, query)
locationMarker = aMap.addMarker(new MarkerOptions()
.anchor(0.5f, 1)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher))
.position(new LatLng(39.908127, 116.375257))
.title("西单为中心点,查其周边"))
locationMarker.showInfoWindow()
//在要搜索的范围中添加一个白色背景&&黑色边线,凸显搜索范围
CircleOptions circleOptions = new CircleOptions()
circleOptions.center(locationMarker.getPosition())
circleOptions.radius(200)
circleOptions.fillColor(Color.WHITE)
circleOptions.strokeColor(Color.BLACK)
circleOptions.strokeWidth(10)
aMap.addCircle(circleOptions)
//设置搜索的范围
poiSearch.setBound(new SearchBound(
new LatLonPoint(locationMarker.getPosition().latitude,
locationMarker.getPosition().longitude), 200))
poiSearch.setOnPoiSearchListener(this)
poiSearch.searchPOIAsyn()
public void onPoiItemSearched(PoiItem arg0, int arg1) {
public void onPoiSearched(PoiResult result, int rCode) {
// 搜索POI的结果
if (result != null && result.getQuery() != null) {
// 是否是同一条
if (result.getQuery().equals(query)) {
poiResult = result
// 取得搜索到的poiitems有多少页
int resultPages = poiResult.getPageCount()
// 取得第一页的poiitem数据,页数从数字0开始
List&PoiItem& poiItems = poiResult.getPois()
if (poiItems != null && poiItems.size() & 0) {
// aMap.clear()
PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems)
poiOverlay.removeFromMap()
poiOverlay.addToMap()
poiOverlay.zoomToSpan()
// 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息
List&SuggestionCity& suggestionCities = poiResult
.getSearchSuggestionCitys()
protected void onResume() {
super.onResume()
mapView.onResume()
protected void onPause() {
super.onPause()
mapView.onPause()
protected void onDestroy() {
super.onDestroy()
mapView.onDestroy()
输入提示搜索
使用一个简单的例子来进行说明
使用一个简单的布局,获取一个AutoCompleteTextView的实例
&?xml version="1.0" encoding="utf-8"?&
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/autocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /&
package com.hang.
import java.util.ArrayL
public class PoiInputInfoActivity extends Activity implements TextWatcher {
AutoCompleteTextView autoCompleteTextV
ArrayAdapter&String&
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_poi_input_info);
autoCompleteTextView=(AutoCompleteTextView)findViewById(R.id.autocomplete);
autoCompleteTextView.addTextChangedListener(this);
autoCompleteTextView.setThreshold(1);
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
public void onTextChanged(CharSequence s, int start, int before, int count) {
public void afterTextChanged(Editable s) {
if (!TextUtils.isEmpty(s.toString())) {
Inputtips inputTips = new Inputtips(this,
new InputtipsListener() {
public void onGetInputtips(final List&Tip& tipList, int rCode) {
if(tipList!=null&&tipList.size()&0){
List&String& listString = new ArrayList&&();
for (int i = 0; i & tipList.size(); i++) {
listString.add(tipList.get(i).getName());
adapter = new ArrayAdapter&String&(
PoiInputInfoActivity.this,
android.R.layout.simple_dropdown_item_1line);
autoCompleteTextView.setAdapter(adapter);
adapter.addAll(listString);
inputTips.requestInputtips(s.toString(), "");
} catch (AMapException e) {
e.printStackTrace();
步行路径规划
步行路径规划可以根据起终点和步行路线的数据,使用WalkRouteOverlay
画出步行路线图层,包括起终点和转弯点,另外也可以自定义起终点和步行转弯点的图标
1.设置搜索条件
通过 WalkRouteQuery(RouteSearch.FromAndTo ft, int mode) 设置搜索条件,参数ft,路径的起终点;mode,计算路径的模式,可选,默认为最快捷
2.发送请求和接收数据
根据给出的起终点坐标和路径的模式(模式类型参照参考手册类 RouteSearch),使用类 RouteSearch 的calculateWalkRouteAsyn(WalkRouteQuery query)
方法进行步行规划路径计算,在 RouteSearch.OnRouteSearchListener 接口回
调方法 void onWalkRouteSearched(WalkRouteResult walkRouteResult,int rCode) 处理步行规划路径结果
做一个Demo,体验一下效果
package com.pansoft.oilgas.
import android.app.A
import android.os.B
import com.amap.api.maps.AM
import com.amap.api.maps.MapV
import com.amap.api.maps.overlay.WalkRouteO
import com.amap.api.services.core.LatLonP
import com.amap.api.services.route.BusRouteR
import com.amap.api.services.route.DriveRouteR
import com.amap.api.services.route.RouteS
import com.amap.api.services.route.WalkP
import com.amap.api.services.route.WalkRouteR
public class QueryPoiActivity extends Activity implements
RouteSearch.OnRouteSearchListener{
MapView mapV
RouteSearch routeS
WalkRouteResult walkRouteR
public void onBusRouteSearched(BusRouteResult busRouteResult, int i) {
public void onDriveRouteSearched(DriveRouteResult driveRouteResult, int i) {
public void onWalkRouteSearched(WalkRouteResult result, int rCode) {
if(rCode == 1000){
if(result != null && result.getPaths() != null && result.getPaths().size() & 0){
walkRouteResult =
WalkPath walkPath = walkRouteResult.getPaths().get(0);
aMap.clear();
WalkRouteOverlay walkRouteOverlay = new WalkRouteOverlay(
this, aMap, walkPath,walkRouteResult.getStartPos(),
walkRouteResult.getTargetPos());
walkRouteOverlay.removeFromMap();
walkRouteOverlay.addToMap();
walkRouteOverlay.zoomToSpan();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView=new MapView(this);
setContentView(mapView);
mapView.onCreate(savedInstanceState);
aMap = mapView.getMap();
routeSearch = new RouteSearch(this);
routeSearch.setRouteSearchListener(this);
LatLonPoint startPoint=new LatLonPoint(36.,117.);
LatLonPoint endPoint=new LatLonPoint(36.,117.);
RouteSearch.FromAndTo fromAndTo=new RouteSearch.FromAndTo(startPoint,endPoint);
int walkMode=RouteSearch.WalkD
RouteSearch.WalkRouteQuery query = new RouteSearch.WalkRouteQuery(fromAndTo, walkMode);
routeSearch.calculateWalkRouteAsyn(query);
protected void onResume() {
super.onResume();
mapView.onResume();
protected void onPause() {
super.onPause();
mapView.onPause();
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
公交路径规划
这个和步行路径规范只有很少的差别,写一个Demo感受一下
package com.pansoft.oilgas.
import android.app.A
import android.os.B
import com.amap.api.maps.AM
import com.amap.api.maps.MapV
import com.amap.api.maps.overlay.BusRouteO
import com.amap.api.maps.overlay.WalkRouteO
import com.amap.api.services.core.LatLonP
import com.amap.api.services.route.BusP
import com.amap.api.services.route.BusRouteR
import com.amap.api.services.route.DriveRouteR
import com.amap.api.services.route.RouteS
import com.amap.api.services.route.WalkP
import com.amap.api.services.route.WalkRouteR
public class QueryPoiActivity extends Activity implements
RouteSearch.OnRouteSearchListener {
MapView mapV
RouteSearch routeS
BusRouteResult busRouteR
public void onBusRouteSearched(BusRouteResult result, int rCode) {
if (rCode == 1000) {
if (result != null && result.getPaths() != null && result.getPaths().size() & 0) {
busRouteResult =
BusPath busPath = busRouteResult.getPaths().get(0);
aMap.clear();
BusRouteOverlay routeOverlay = new BusRouteOverlay(
this, aMap, busPath, busRouteResult.getStartPos(),
busRouteResult.getTargetPos());
routeOverlay.removeFromMap();
routeOverlay.addToMap();
routeOverlay.zoomToSpan();
public void onDriveRouteSearched(DriveRouteResult driveRouteResult, int i) {
public void onWalkRouteSearched(WalkRouteResult result, int rCode) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView = new MapView(this);
setContentView(mapView);
mapView.onCreate(savedInstanceState);
aMap = mapView.getMap();
routeSearch = new RouteSearch(this);
routeSearch.setRouteSearchListener(this);
LatLonPoint startPoint = new LatLonPoint(36., 117.);
LatLonPoint endPoint = new LatLonPoint(36., 117.);
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(startPoint, endPoint);
int busMode = RouteSearch.BusLeaseC
String city = "济南";
int calculateNight = 0;
RouteSearch.BusRouteQuery query = new RouteSearch.BusRouteQuery(fromAndTo, busMode, city, calculateNight);
routeSearch.calculateBusRouteAsyn(query);
protected void onResume() {
super.onResume();
mapView.onResume();
protected void onPause() {
super.onPause();
mapView.onPause();
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
驾车路径规划
驾车路径规划可以根据起终点和驾车路线的数据,使用 DrivingRouteOverlay 画出驾车路线图层,包括起终点和转弯点,另外也可以自定义起终点和驾车转弯点的图标
1.设置搜索条件
目前驾车路径规划支持途经点、避让区域以及支持选择一条避让道路,通过
DriveRouteQuery(RouteSearch.FromAndTo ft, int mode, List
passedByPoints, List avoidpolygons, String avoidRoad) 设置搜索条件
o 参数 ft,路径的起终点;
o mode,计算路径的模式,可选,默认为速度优先;
o passedByPoints,途经点,可选;
o avoidpolygons,避让区域,可选;
2.发送请求和接收数据
使用类 RouteSearch 的 calculateDriveRouteAsyn(DriveRouteQuery query)
方法进行驾车规划路径计算,在 RouteSearch.OnRouteSearchListener 接口回
调方法 void onDriveRouteSearched(DriveRouteResult driveRouteResult,int
rCode) 处理驾车路径规划结果
不罗嗦了,写一个Demo感受一下
package com.pansoft.oilgas.
import android.app.A
import android.os.B
import com.amap.api.maps.AM
import com.amap.api.maps.MapV
import com.amap.api.maps.overlay.DrivingRouteO
import com.amap.api.services.core.LatLonP
import com.amap.api.services.route.BusRouteR
import com.amap.api.services.route.DriveP
import com.amap.api.services.route.DriveRouteR
import com.amap.api.services.route.RouteS
import com.amap.api.services.route.WalkRouteR
public class QueryPoiActivity extends Activity implements
RouteSearch.OnRouteSearchListener {
MapView mapV
RouteSearch routeS
DriveRouteResult driveRouteR
public void onBusRouteSearched(BusRouteResult result, int rCode) {
public void onDriveRouteSearched(DriveRouteResult result, int rCode) {
if(rCode == 1000){
if(result != null && result.getPaths() != null && result.getPaths().size() & 0){
driveRouteResult =
DrivePath drivePath = driveRouteResult.getPaths().get(0);
aMap.clear();
DrivingRouteOverlay drivingRouteOverlay = new DrivingRouteOverlay(
this, aMap, drivePath,driveRouteResult.getStartPos(),
driveRouteResult.getTargetPos());
drivingRouteOverlay.removeFromMap();
drivingRouteOverlay.addToMap();
drivingRouteOverlay.zoomToSpan();
public void onWalkRouteSearched(WalkRouteResult result, int rCode) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView = new MapView(this);
setContentView(mapView);
mapView.onCreate(savedInstanceState);
aMap = mapView.getMap();
routeSearch = new RouteSearch(this);
routeSearch.setRouteSearchListener(this);
LatLonPoint startPoint = new LatLonPoint(36., 117.);
LatLonPoint endPoint = new LatLonPoint(36., 117.);
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(startPoint, endPoint);
int drivingMode = RouteSearch.DrivingD
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, drivingMode, null, null, "");
routeSearch.calculateDriveRouteAsyn(query);
protected void onResume() {
super.onResume();
mapView.onResume();
protected void onPause() {
super.onPause();
mapView.onPause();
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
公交线路查询
您可以根据线路名称、途经站点、线路ID查询公交线路信息,根据线路名称和ID可以通过如下方法查询:
1.设置搜索条件
根据 BusLineSearch(Context act, new BusQuery(String query,
BusLineQuery.SearchType ctgr, String city)) 创建一个 BusLineSearch 对象,并设置查询条件,查询类型参数 ctgr 此处设置为 :
BusLineQuery.SearchType.BY_LINE_NAME(名称查询)或
BusLineQuery.SearchType. BY_LINE_ID(ID查询)
2.发送请求和接收数据
使用 BusLineSearch.searchBusLineAsyn() 搜索公交线路,在
BusLineSearch.OnBusLineSearchListener 的接口回调方法
onBusLineSearched(BusLineResult busLineResult, int rCode) 处理返回结果,
当根据线路名称搜索无结果时,会自动匹配关键字为途经点名称进行搜索
一个小Demo,看一下效果吧
package com.pansoft.oilgas.
import android.app.A
import android.os.B
import com.amap.api.services.busline.BusLineI
import com.amap.api.services.busline.BusLineQ
import com.amap.api.services.busline.BusLineR
import com.amap.api.services.busline.BusLineS
import java.util.ArrayL
import java.util.L
public class MainActivity extends Activity implements
BusLineSearch.OnBusLineSearchListener {
BusLineQuery busLineQ
BusLineResult busLineR
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
busLineQuery = new BusLineQuery("116", BusLineQuery.SearchType.BY_LINE_NAME, "济南");
busLineQuery.setPageSize(10);
busLineQuery.setPageNumber(0);
BusLineSearch busLineSearch = new BusLineSearch(this, busLineQuery);
busLineSearch.setOnBusLineSearchListener(this);
busLineSearch.searchBusLineAsyn();
public void onBusLineSearched(BusLineResult result, int rCode) {
if (rCode == 1000) {
if (result != null && result.getQuery() != null &&
result.getQuery().equals(busLineQuery)) {
if (result.getQuery().getCategory() == BusLineQuery.SearchType.BY_LINE_NAME) {
if (result.getPageCount() & 0 && result.getBusLines() != null
&& result.getBusLines().size() & 0) {
busLineResult =
List&BusLineItem& lineItems = result.getBusLines();
ArrayList&BusLineItem& arrayList = new ArrayList&&();
arrayList.addAll(lineItems);
BusLineDialogFragment busLineDialogFragment = new BusLineDialogFragment();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("data", arrayList);
busLineDialogFragment.setArguments(bundle);
busLineDialogFragment.show(getFragmentManager(), "xxxx");
package com.pansoft.oilgas.gaodenavigation
import android.app.Activity
import android.app.AlertDialog
import android.app.Dialog
import android.app.DialogFragment
import android.content.DialogInterface
import android.os.Bundle
import android.os.Parcel
import com.amap.api.services.busline.BusLineItem
import com.amap.api.services.busline.BusLineQuery
import com.amap.api.services.busline.BusLineResult
import com.amap.api.services.busline.BusLineSearch
import java.util.ArrayList
import java.util.List
public class BusLineDialogFragment extends DialogFragment {
private String[] busArray
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
ArrayList&BusLineItem& busLineResultList = getArguments().getParcelableArrayList("data")
busArray = new String[busLineResultList.size()]
for (int j = 0
busArray[j] = busLineResultList.get(j).getBusLineName()
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
builder.setItems(busArray, null)
builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
builder.setTitle("查询结果")
return builder.show()
不熟悉DialogFragment的同学,请参考:
前面那个例子挺无聊的,下面做一个有点实际应用价值的——查询经过某一个站点的所有公交线路
如果通过途经站点查询可以使用如下方法:
1.设置搜索条件
根据 BusStationSearch(Context act, new BusQuery(String query, String
city)) 创建一个 BusStationSearch 对象,并设置查询条件
2.发送请求和接收数据
通过设置 busStationSearch.setOnBusLineSearchListener(this)监听,使用
BusStationSearch.searchBusStationAsyn() 搜索结果,并通过
OnBusStationSearchListener.onBusStationSearched() 返回数据,结果返回车站ID、车站经纬度坐标、车站区域编码、车站名称、经过此公交站的公交路线等信息
下面咱们查询一下途经大济南齐鲁软件园的公交线路
package com.pansoft.oilgas.
import android.app.A
import android.os.B
import com.amap.api.services.busline.BusStationI
import com.amap.api.services.busline.BusStationQ
import com.amap.api.services.busline.BusStationR
import com.amap.api.services.busline.BusStationS
import java.util.ArrayL
import java.util.L
public class MainActivity extends Activity implements
BusStationSearch.OnBusStationSearchListener {
BusStationQuery busStationQ
BusStationSearch busStationS
BusStationResult busStationR
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
busStationQuery = new BusStationQuery("齐鲁软件园", "济南");
busStationSearch = new BusStationSearch(this, busStationQuery);
busStationSearch.setOnBusStationSearchListener(this);
busStationSearch.searchBusStationAsyn();
public void onBusStationSearched(BusStationResult result, int rCode) {
if (rCode == 1000) {
if (result != null && result.getQuery() != null &&
result.getQuery().equals(busStationQuery)) {
if (result.getPageCount() & 0 && result.getBusStations() != null
&& result.getBusStations().size() & 0) {
busStationResult =
List&BusStationItem& stationItems = result.getBusStations();
ArrayList&BusStationItem& arrayList = new ArrayList&&();
arrayList.addAll(stationItems);
BusStationDialogFragment busStationDialogFragment = new BusStationDialogFragment();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("data", arrayList);
busStationDialogFragment.setArguments(bundle);
busStationDialogFragment.show(getFragmentManager(), "xxxx");
package com.pansoft.oilgas.
import android.app.AlertD
import android.app.D
import android.app.DialogF
import android.content.DialogI
import android.os.B
import com.amap.api.services.busline.BusStationI
import java.util.ArrayL
public class BusStationDialogFragment extends DialogFragment {
private String[] busA
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList&BusStationItem& stationList = getArguments().getParcelableArrayList("data");
ArrayList&String& busLineList = new ArrayList&&();
for (int j = 0; j & stationList.size(); j++) {
for (int jj = 0; jj & stationList.get(j).getBusLineItems().size(); jj++) {
busLineList.add(stationList.get(j).getBusLineItems().get(jj).getBusLineName());
busArray = new String[busLineList.size()];
for (int j = 0; j & busArray. j++) {
busArray[j] = busLineList.get(j);
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setItems(busArray, null);
builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
dismiss();
builder.setTitle("查询结果");
return builder.show();
坐标/地址查询
目前高德地图API仅支持中国范围内的地理及逆地理编码,且只支持中文的中国地图数据,不支持英文或汉语拼音的中国地图数据
1.地理编码
地理编码是将中文地址(或地名描述)转换为地理坐标的功能,根据给定的地理名称和查询城市,返回地理编码的结果列表
2.逆地理编码
逆地理编码时将地理坐标转换为中文地址(地名描述)的功能,逆地理编码搜索时,还会返回坐标点附近的 POI(兴趣点)、道路以及交叉路口等信息,目前高德地图 Android SDK 支持高德类型坐标、 GPS 坐标的逆地理编码查询
下面通过一个例子来讲解一下使用方法
package com.pansoft.oilgas.gaodenavigation
import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import com.amap.api.services.busline.BusStationItem
import com.amap.api.services.busline.BusStationQuery
import com.amap.api.services.busline.BusStationResult
import com.amap.api.services.busline.BusStationSearch
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.RegeocodeQuery
import com.amap.api.services.geocoder.RegeocodeResult
import java.util.ArrayList
import java.util.List
public class MainActivity extends Activity implements
GeocodeSearch.OnGeocodeSearchListener {
final String tag = MainActivity.class.getSimpleName()
GeocodeSearch geocoderSearch
private TextView textView
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
textView = new TextView(this)
setContentView(textView)
geocoderSearch = new GeocodeSearch(this)
geocoderSearch.setOnGeocodeSearchListener(this)
GeocodeQuery query = new GeocodeQuery("齐鲁软件园", "济南")
geocoderSearch.getFromLocationNameAsyn(query)
//2.逆地理编码请求
LatLonPoint latLonPoint = new LatLonPoint(36.67264, 117.133608)
RegeocodeQuery query2 = new RegeocodeQuery(latLonPoint, 200, GeocodeSearch.AMAP)
geocoderSearch.getFromLocationAsyn(query2)
public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
if (rCode == 1000) {
if (result != null && result.getRegeocodeAddress() != null
&& result.getRegeocodeAddress().getFormatAddress() != null) {
textView.append(result.getRegeocodeQuery().getPoint() + ":\n")
textView.append("在" + result.getRegeocodeAddress().getFormatAddress() + "附近\n")
public void onGeocodeSearched(GeocodeResult result, int rCode) {
if (rCode == 1000) {
if (result != null && result.getGeocodeAddressList() != null
&& result.getGeocodeAddressList().size() & 0) {
GeocodeAddress address = result.getGeocodeAddressList().get(0)
String addressName = "经纬度值:" + address.getLatLonPoint()
+ "\n位置描述:" + address.getFormatAddress()
Log.d(tag, addressName)
textView.append(address.getFormatAddress() + "的经纬度坐标为:\n")
textView.append(address.getLatLonPoint() + "\n")
图片覆盖层(GroundOverlay)
添加图片覆盖层需要通过设置中心点或者图片区域来确定图片覆盖层的位置,初始化一个 GroundOverlayOptions 对象来设置图片层图片区域、透明度、锚点、要显示的图片,使用 AMap.addGroundOverlay(GroundOverlayOptions) 将此图片层添加到地图,图片覆盖层的属性如下:
o anchor图片和指定点的对齐方式,[0,0]是左上角,[1,1]是右下角如果不设置,默认为[0.5,0.5]图片的中心点
o bearing图片覆盖层相对锚点从正北顺时针的旋转角度
o image此图片覆盖层的图片
o visible 设置“false ” ,线不可见
o position根据描点和宽高设置图片层,在显示时,图片会被缩放来适应指定的尺寸
o transparency图片覆盖层的透明度,默认透明度为0,不透明
啰嗦一个完整的例子,这里只有addOverlayToMap是添加图覆层的方法,其都是加载地图的逻辑
package com.pansoft.oilgas.gaodenavigation
import android.app.Activity
import android.os.Bundle
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.GroundOverlay
import com.amap.api.maps.model.GroundOverlayOptions
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLngBounds
public class QueryPoiActivity extends Activity {
MapView mapView
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
mapView = new MapView(this)
setContentView(mapView)
mapView.onCreate(savedInstanceState)
aMap = mapView.getMap()
addOverlayToMap()
private void addOverlayToMap() {
// 设置当前地图显示为北京市恭王府
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.936713, 116.386475), 19))
//设置图片的显示区域
LatLngBounds bounds = new LatLngBounds.Builder()
.include(new LatLng(39.935029, 116.384377))
.include(new LatLng(39.939577, 116.388331)).build()
GroundOverlay groundoverlay = aMap.addGroundOverlay(new GroundOverlayOptions()
.anchor(0.5f, 0.5f).transparency(0.1f)
.image(BitmapDescriptorFactory.fromResource(R.drawable.bg_ground))
.positionFromBounds(bounds))
protected void onResume() {
super.onResume()
mapView.onResume()
protected void onPause() {
super.onPause()
mapView.onPause()
protected void onDestroy() {
super.onDestroy()
mapView.onDestroy()
在这里bg_ground.png,就是一个简单的白色色块
o icons 设置标记图标的动画帧列表
o period设置标记动画刷新一次图片资源的周期
来个小例子感受一下,addGifIcon是关键,其他是加载地图的部分
package com.pansoft.oilgas.gaodenavigation
import android.app.Activity
import android.os.Bundle
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.GroundOverlay
import com.amap.api.maps.model.GroundOverlayOptions
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLngBounds
import com.amap.api.maps.model.Marker
import com.amap.api.maps.model.MarkerOptions
import java.util.ArrayList
public class QueryPoiActivity extends Activity {
MapView mapView
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
mapView = new MapView(this)
setContentView(mapView)
mapView.onCreate(savedInstanceState)
aMap = mapView.getMap()
addGifIcon()
public void addGifIcon(){
//声明一个动画帧集合
ArrayList giflist = new ArrayList()
//添加每一帧图片
giflist.add(BitmapDescriptorFactory.fromResource(R.drawable.navigation_left))
giflist.add(BitmapDescriptorFactory.fromResource(R.drawable.navigation_up))
giflist.add(BitmapDescriptorFactory.fromResource(R.drawable.navigation_down))
//设置远小近大效果,2.1.0版本新增;设置刷新一次图片资源的周期
Marker beijingMarker= aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
.position(new LatLng(39.,116.)).title("北京市")
.snippet("北京市:39.,116.").icons(giflist)
.perspective(true).draggable(true).period(50))
beijingMarker.showInfoWindow()
// 设置默认显示一个info window
protected void onResume() {
super.onResume()
mapView.onResume()
protected void onPause() {
super.onPause()
mapView.onPause()
protected void onDestroy() {
super.onDestroy()
mapView.onDestroy()
用到的图片资源有:
这里参考了高德地图官方文档的很多内容,但例子都经过了自己验证的!
没有更多推荐了,}

我要回帖

更多关于 高德导航官网免费版 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信