當前位置:首頁 » 安卓系統 » 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開發如何用高德地圖進行模擬定位

熱點內容
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:88
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:502
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:651
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:477
電腦主伺服器怎麼開機 發布:2024-09-20 07:19:07 瀏覽:728
2022款瑞虎升級哪些配置 發布:2024-09-20 06:59:07 瀏覽:265
資料庫與asp 發布:2024-09-20 06:55:25 瀏覽:727
python解釋編譯 發布:2024-09-20 06:52:57 瀏覽:648
舞蹈豐收腳本 發布:2024-09-20 06:36:26 瀏覽:595
linux進程埠號 發布:2024-09-20 06:36:11 瀏覽:81