当前位置:首页 » 安卓系统 » android高德地图开发

android高德地图开发

发布时间: 2022-01-10 18:28:35

‘壹’ android 高德地图的开发 移动地图流畅性

这里不得不说下个人情况,此项目是他人开发,而开发人员已经不在公司,bug转发给我了。自己之前也没怎么使用过高德,主要使用的是谷歌地图和mapbox。在修改这个bug的时候,思绪会受谷歌api一些影响,因为一直觉得他们的api都差不多。现在我打开自己的页面,然后拖动marker,拖动结束我会打印一下经纬度,然后把这个经纬度复制下来,并在高德的官方地图上去搜索获取到的这个经纬度。结果确实一直都是有偏差的,而且还偏差值每次都不同。

‘贰’ 如何使用高德Android SDK进行LBS的开发

一、如何使用AndroidSDK进行开发01——LBS开放平台简介及环境搭建

二、如何使用AndroidSDK进行开发02—marker标记

三、如何使用Android SDK进行开发03-地图Overlay添加

四、如何使用Android SDK进行开发04-搜索功能

‘叁’ android开发如何用高德地图进行模拟定位.

一、 要实现高德地图定位呢,首先需要做好以下几步准备:
1. 在高德开放平台注册帐号

2. 在开发中下载Android平台下的地图SDK和定位SDK文件
进入相关下载下载自己想要的功能或文件,图只是截取了地图SDK的页面,定位SDK也是一样,按自己想要的文件下载。下载完成后解压得到:
- 3D地图包解压后得到:3D地图显示包“AMap_3DMap_VX.X.X_时间.jar”和库文件夹(包含armeabi、arm64-v8a等库文件)。
- 2D地图包解压后得到:2D地图显示包“AMap_2DMap_VX.X.X_时间.jar ”
- 定位SDK下载并解压得到定位包“AMap_Location_V2.x.x.jar“
3. 添加jar包,将jar包放入工程的libs目录下。

对于每个jar文件,右键-选择Add As Library,导入到工程中。或者使用菜单栏 选择 File ->Project Structure->Moles-> Dependencies。点击绿色的加号选择File dependency. 然后选择要添加的jar包即可,此时build.gradle中会自动生成如下信息。

创建自己的应用(创建过程内需要的SHA1已经的博客讲过)

开发环境已经配置好了,接下来就是敲代码了。
二、 首先我们要做的就是将地图显示出来,通过以下几步操作,即可在应用中使用高德地图SDK:
第一步:添加用户key 在工程的“ AndroidManifest.xml ”文件如下代码中添加您的用户 Key。
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"

android:theme="@style/AppTheme">
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="" />123456789

第二步:添加所需权限 在工程的“ AndroidManifest.xml ”文件中进行添加。
//地图包、搜索包需要的基础权限

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

//定位包、导航包需要的额外权限(注:基础权限也需要)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />1234567891011121314

第三步:在布局xml文件中添加地图控件。
<com.amap.api.maps2d.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />1234

第四步,创建地图Activity,管理地图生命周期。
public class MainActivity extends Activity {
private MapView mMapView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取地图控件引用
mMapView = (MapView) findViewById(R.id.map_view);
//在activity执行onCreate时执行mMapView.o

mMapView.onCreate(savedInstanceState);
}
@Override
protected void onDestroy() {
super.onDestroy();
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
mMapView.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
//在activity执行onResume时执行mMapView.onResume (),实现地图生命周期管理
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
//在activity执行onPause时执行mMapView.onPause (),实现地图生命周期管理
mMapView.onPause();
}
@Override

protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState),实现地图生命周期管理
mMapView.onSaveInstanceState(outState);
}

}

注意:一定要有mMapView.onCreate(savedInstanceState);
第二步:启动定位功能:
1. 在主线程中获得地图对象AMap,并设置定位监听且实现LocationSource接口:

public class MainActivity extends Activity implements LocationSource{1
if (aMap == null) {
aMap = mMapView.getMap();
//设置显示定位按钮 并且可以点击
UiSettings settings = aMap.getUiSettings();
aMap.setLocationSource(this);//设置了定位的监听,这里要实现LocationSource接口
// 是否显示定位按钮
settings.setMyLocationButtonEnabled(true);
aMap.setMyLocationEnabled(true);//显示定位层并且可以触发定位,默认是flase
}123456789
2. 配置定位参数,启动定位

//初始化定位

mLocationClient = new AMapLocationClient(getApplicationContext());
//设置定位回调监听,这里要实现AMapLocationListener接口,AMapLocationListener接口只有onLocationChanged方法可以实现,用于接收异步返回的定位结果,参数是AMapLocation类型。
mLocationClient.setLocationListener(this);
//初始化定位参数
mLocationOption = new AMapLocationClientOption();
//设置定位模式为Hight_Accuracy高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//设置是否返回地址信息(默认返回地址信息)
mLocationOption.setNeedAddress(true);
//设置是否只定位一次,默认为false
mLocationOption.setOnceLocation(false);
//设置是否强制刷新WIFI,默认为强制刷新
mLocationOption.setWifiActiveScan(true);
//设置是否允许模拟位置,默认为false,不允许模拟位置
mLocationOption.setMockEnable(false);
//设置定位间隔,单位毫秒,默认为2000ms
mLocationOption.setInterval(2000);
//给定位客户端对象设置定位参数
mLocationClient.setLocationOption(mLocationOption);
//启动定位
mLocationClient.startLocation();

高精度定位模式:
在这种定位模式下,将同时使用高德网络定位和GPS定位,优先返回精度高的定位

低功耗定位模式:
在这种模式下,将只使用高德网络定位

仅设备定位模式:
在这种模式下,将只使用GPS定位。

3. 实现AMapLocationListener接口,获取定位结果:

public class MainActivity extends Activity implem

@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
//定位成功回调信息,设置相关消息
aMapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见官方定位类型表
aMapLocation.getLatitude();//获取纬度
aMapLocation.getLongitude();//获取经度
aMapLocation.getAccuracy();//获取精度信息
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(aMapLocation.getTime());
df.format(date);//定位时间
aMapLocation.getAddress();//地址,如果option中设置isNeedAddress为false,则没有此结果,网络定位结果中会有地址信息,GPS定位不返回地址信息。
aMapLocation.getCountry();//国家信息
aMapLocation.getProvince();//省信息
aMapLocation.getCity();//城市信息
aMapLocation.getDistrict();//城区信息
aMapLocation.getStreet();//街道信息
aMapLocation.getStreetNum();//街道门牌号信息
aMapLocation.getCityCode();//城市编码
aMapLocation.getAdCode();//地区编码

// 如果不设置标志位,此时再拖动地图时,它会不断将地图移动到当前的位置
if (isFirstLoc) {
//设置缩放级别
aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
//将地图移动到定位点
aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude())));
//点击定位按钮 能够将地图的中心移动到定位点
mListener.onLocationChanged(aMapLocation);
//获取定位信息
StringBuffer buffer = new StringBuffer();
buffer.append(aMapLocation.getCountry() + ""
+ aMapLocation.getProvince() + ""
+ aMapLocation.getCity() + ""
+ aMapLocation.getProvince()
+ aMapLocation.getDistrict() + ""
+ aMapLocation.getStreet() + ""
+ aMapLocation.getStreetNum());
Toast.makeText(getApplicationContext(), buffer.toString(), Toast.LENGTH_LONG).show();
isFirstLoc = false;
}
} else {
//显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。
Log.e("AmapError", "location Error, ErrCode:"
+ aMapLocation.getErrorCode() + ", errInfo:"
+ aMapLocation.getErrorInfo());
Toast.makeText(getApplicationContext(), "定位失败", Toast.LENGTH_LONG).show();
}
}
}3839404142434445464748495051
4.关于停止定位

@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
//mLocationClient.stopLocation();//停止定位
mLocationClient.onDestroy();//销毁定位客户端。
//销毁定位客户端之后,若要重新开启定位请重新New一个AMapLocationClient对象。
}

//激活定位
@Override
public void activate(OnLocationChangedListener onLocationChangedListener) {
mListener = onLocationChangedListener;
}

@Override
public void deactivate() {
mListener = null;
}12345678910111213141516171819

‘肆’ 高德android导航开发,要怎么自定义路线

定义不了。高德导航和高德地图的真正区别在于。
1高德导航专用于行车打造的,可以离线搜索,离线导航,也可以在线导航,搜索更新的POI,高德地图只能在线导航,在线搜索。
2.导航是收费,高德地图是免费,用于步行,公交换乘比较方便。其实现在高德地图对驾驶导航一样的方便好用。
3.高德导航不费流量,高德地图现在都是本地离线地图,流量可以忽略不计。
4.高德导航和高德地图是两个部门开发的。

‘伍’ android 百度地图和高德地图为什么比自己开发的好那么多

你用网络搜人家当然说网络地图好了,
你用神马搜索就会提示高德地图好。
这个其实不用太在意,一般情况下这两个软件地图都够用,
你可以都试试感觉一下你用哪个更舒服些。

‘陆’ 高德地图,android开发中,怎么用经纬度来显示地图

首先创建工程,并在工程Build Path>Configure Build Path…>libraries 中选择“Add Externel JARs…”,选定

MapApi.jar,点击OK,这样就可以将高德地图Android API 库文件引入。然后在工程Build Path>Configure Build

Path…>Order and Export 中将引入的库文件MapApi.jar 选中,点击OK,这样您就可以在您的程序中使用高德地图API

了。

二、我们在不熟悉的情况下、先尽量多的添加此软件应用权限;所以在mainifest中添加如下代码;插入的位置在

<application的代码之前。

Java代码
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>

三、接着就要在res文件下的layout中添加界面布局了。其代码如下、你可以完全复制进去。

Java代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!--添加文本输入框,查找地址-->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="经度"/>
<EditText android:layout_height="fill_parent"
android:layout_width="100px"
android:id="@+id/longitude"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="纬度"/>
<EditText android:layout_height="fill_parent"
android:layout_width="100px"
android:id="@+id/latitude"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查找"
android:id="@+id/button"/>
</LinearLayout>

<com.amap.mapapi.map.MapView android:id="@+id/mapView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:clickable="true"
/>
</LinearLayout>

四、最后就是软件的主程序部分了、里面需要的类和方法不多,主要以按钮的监听器和地图的界面实现为主

Java代码
public void onCreate(Bundle savedInstanceState) {
// this.setMapMode(MAP_MODE_VECTOR);//设置地图为矢量模式

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setBuiltInZoomControls(true); // 设置启用内置的缩放控件
mMapController = mMapView.getController(); // 得到mMapView
// 的控制权,可以用它控制和驱动平移和缩放
point = new GeoPoint((int) (39.982378 * 1E6), (int) (116.304923 * 1E6)); // 用给定的经纬度构造一个GeoPoint,单位是微度(度*
// 1E6)
// 按钮添加监听器
button_location = (Button) findViewById(R.id.location);
longitude = (EditText) findViewById(R.id.longitude);
latite = (EditText) findViewById(R.id.latitude);
locationListener = new OnClickListener() {
public void onClick(View e) {
if (e.equals(button_location)) {
// 得到文本输入框的中经纬 度坐标值
String latStr = longitude.getText().toString();
// 将得到的字符串转成数值
double lat = Integer.parseInt(latStr);
String lngStr = latite.getText().toString();
double lng = Integer.parseInt(lngStr);
//转成经纬度坐标
lat=lat*1E6;
lng=lng*1E6;
// 用给定的经纬度构造一个GeoPoint,单位是微度(度*1E6)
point = new GeoPoint((int) (lat), (int) (lng));
mMapController.setCenter(point); // 设置地图中心点
mMapController.setZoom(12); // 设置地图zoom 级别
// 添加地图覆盖物
// MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判断是否发现位置提供者
mylocTest.enableCompass(); // 打开指南针
mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物
}
}
};
// 按钮添加监听器
button_location.setOnClickListener(locationListener);
mMapController.setCenter(point); // 设置地图中心点
mMapController.setZoom(12); // 设置地图zoom 级别
// 添加地图覆盖物
mylocTest = new MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判断是否发现位置提供者
mylocTest.enableCompass(); // 打开指南针
mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物
}
//另外一个添加界面覆盖物的类:

public class MyLocationOverlayProxy extends com.amap.mapapi.map.MyLocationOverlay{

private Location mLocation;
protected final Paint mPaint = new Paint();
protected final Paint mCirclePaint = new Paint();
private Bitmap gps_marker=null;
private Point mMapCoords = new Point();
private final float gps_marker_CENTER_X;
private final float gps_marker_CENTER_Y;
private final LinkedList<Runnable> mRunOnFirstFix = new LinkedList<Runnable>();
public MyLocationOverlayProxy(amap amap, MapView mMapView) {

super(amap, mMapView);
gps_marker = ((BitmapDrawable) amap.getResources().getDrawable(
R.drawable.marker_gpsvalid)).getBitmap();
gps_marker_CENTER_X = gps_marker.getWidth() / 2 - 0.5f;
gps_marker_CENTER_Y= gps_marker.getHeight() / 2 - 0.5f;
}

public boolean runOnFirstFix(final Runnable runnable) {
if (mLocation != null) {
new Thread(runnable).start();
return true;
} else {
mRunOnFirstFix.addLast(runnable);
return false;
}
}

public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mLocation = location;
for(final Runnable runnable : mRunOnFirstFix) {
new Thread(runnable).start();
}
mRunOnFirstFix.clear();
super.onLocationChanged(location);
}

protected void drawMyLocation(Canvas canvas, MapView mapView, final Location mLocation,
GeoPoint point, long time) {
Projection pj=mapView.getProjection();
if (mLocation != null) {
mMapCoords=pj.toPixels(point, null);
final float radius = pj.metersToEquatorPixels(mLocation.getAccuracy());
this.mCirclePaint.setAntiAlias(true);
this.mCirclePaint.setARGB(35, 131, 182, 222);
this.mCirclePaint.setAlpha(50);
this.mCirclePaint.setStyle(Style.FILL);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
this.mCirclePaint.setARGB(225, 131, 182, 222);
this.mCirclePaint.setAlpha(150);
this.mCirclePaint.setStyle(Style.STROKE);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
canvas.drawBitmap(gps_marker, mMapCoords.x-gps_marker_CENTER_X, mMapCoords.y-gps_marker_CENTER_Y, this.mPaint);
}
}

}

‘柒’ android开发 调用高德地图SDK

高德地图使用的是面向接口的框架,其ViewMap类作为核心类,需要重写Activity生命周期的所有方法,这要求开发者具备面向对象多态性,继承性的功底。如果不理解常用的设计模式和架构,对于该平台的掌握会稍微吃力。

‘捌’ android 高德地图上做开发,四个点之间距离最短的走法,如何实现....

如何能实现 四个点之间都走过而且距离是最短的,目前实现的只能是两个点,一个起点,一个终点间的距离,并且在做把终点再当做起点到另一点的终点时,画的线会被后者给覆盖了;所以就看不到前面线路还有距离了..

GeoPoint startPoint = new GeoPoint(39908717, 116397516);
GeoPoint point1 = new GeoPoint(39908717,116459516);
FromAndTo fromAndTo = new FromAndTo(startPoint, point1);

try {
//Route.DrivingLeastDistance 为最短的行驶路线
List<Route> route = Route.calculateRoute(RouteDemo.this, fromAndTo,Route.DrivingLeastDistance);
// 构造RouteOverlay 参数为MapActivity cnt, Route rt。这里只取了查到路径的第一条。
if (route.size() > 0) {
routeOverlay = new RouteOverlay(RouteDemo.this, route.get(0));
routeOverlay.registerRouteMessage(rmHandler);// 注册人消息处理函数
routeOverlay.addToMap(mMapView);// 加入地图
routeOverlay.enableDrag(false);

int length = routeOverlay.getRoute().getLength();//获取路线长度
Log.e("route--length = >","总长为:"+length);
Toast.makeText(this, "length = "+length, Toast.LENGTH_SHORT);
}
} catch (AMapException e) {
e.printStackTrace();
}

当再调用一次这个方法时
routeOverlay.addToMap(mMapView);// 加入地图

会覆盖前面的那条 路线

如何能够实现四点连在一起的的经过线路呢?

‘玖’ 高德android导航开发,要怎么自定义路线。。

目前高德地图里自定义路线还不完善,现在只可以设置3个点。一个是起点,一个是途经点,还有一个是终点,我之前也是想设计自定义路线,发现设不设都无所谓,你怎么走系统都会为你规划到正确的路线上。你用高德地图走习惯了,他也有记忆功能,知道你平时喜欢走的路线,以后就会按你习惯的路线进行规划路线了。希望能帮到你。

‘拾’ android开发如何用高德地图进行模拟定位

一、 要实现高德地图定位呢,首先需要做好以下几步准备: 1 在高德开放平台注册帐号 2 在开发中下载Android平台下的地图SDK和定位SDK文件 进入相关下载下载自己想要的功能或文件,图只是截取了地图SDK的页面,定位SDK也是一样,按自己想要的文android开发如何用高德地图进行模拟定位

热点内容
单片机android 发布:2024-09-20 09:07:24 浏览:759
如何提高三星a7安卓版本 发布:2024-09-20 08:42:35 浏览:659
如何更换服务器网站 发布:2024-09-20 08:42:34 浏览:306
子弹算法 发布:2024-09-20 08:41:55 浏览:284
手机版网易我的世界服务器推荐 发布:2024-09-20 08:41:52 浏览:812
安卓x7怎么边打游戏边看视频 发布:2024-09-20 08:41:52 浏览:158
sql数据库安全 发布:2024-09-20 08:31:32 浏览:89
苹果连接id服务器出错是怎么回事 发布:2024-09-20 08:01:07 浏览:503
编程键是什么 发布:2024-09-20 07:52:47 浏览:654
学考密码重置要求的证件是什么 发布:2024-09-20 07:19:46 浏览:479