當前位置:首頁 » 安卓系統 » android高德地圖

android高德地圖

發布時間: 2022-01-08 16:18:16

Ⅰ 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

Ⅱ 在安卓開發中如何在自己設置的經緯度顯示到高德地圖上中心點

首先創建工程,並在工程BuildPath>ConfigureBuildPath…>libraries中選擇「AddExternelJARs…」,選定MapApi.jar,點擊OK,這樣就可以將高德地圖AndroidAPI庫文件引入。然後在工程BuildPath>ConfigureBuildPath…>OrderandExport中將引入的庫文件MapApi.jar選中,點擊OK,這樣您就可以在您的程序中使用高德地圖API了。二、我們在不熟悉的情況下、先盡量多的添加此軟體應用許可權;所以在mainifest中添加如下代碼;插入的位置在三、接著就要在res文件下的layout中添加界面布局了。其代碼如下、你可以完全復制進去。Java代碼四、最後就是軟體的主程序部分了、裡面需要的類和方法不多,主要以按鈕的監聽器和地圖的界面實現為主Java代碼publicvoidonCreate(BundlesavedInstanceState){//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=newGeoPoint((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=newOnClickListener(){publicvoidonClick(Viewe){if(e.equals(button_location)){//得到文本輸入框的中經緯度坐標值StringlatStr=longitude.getText().toString();//將得到的字元串轉成數值doublelat=Integer.parseInt(latStr);StringlngStr=latite.getText().toString();doublelng=Integer.parseInt(lngStr);//轉成經緯度坐標lat=lat*1E6;lng=lng*1E6;//用給定的經緯度構造一個GeoPoint,單位是微度(度*1E6)point=newGeoPoint((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=newMyLocationOverlay(this,mMapView);mylocTest.enableMyLocation();//判斷是否發現位置提供者mylocTest.enableCompass();//打開指南針mMapView.getOverlays().add(mylocTest);//添加定位覆蓋物}//另外一個添加界面覆蓋物的類:.amap.mapapi.map.MyLocationOverlay{privateLocationmLocation;protectedfinalPaintmPaint=newPaint();=newPaint();privateBitmapgps_marker=null;privatePointmMapCoords=newPoint();privatefinalfloatgps_marker_CENTER_X;privatefinalfloatgps_marker_CENTER_Y;=newLinkedList();publicMyLocationOverlayProxy(amapamap,MapViewmMapView){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;}publicbooleanrunOnFirstFix(finalRunnablerunnable){if(mLocation!=null){newThread(runnable).start();returntrue;}else{mRunOnFirstFix.addLast(runnable);returnfalse;}}publicvoidonLocationChanged(Locationlocation){//TODOAuto-generatedmethodstubmLocation=location;for(finalRunnablerunnable:mRunOnFirstFix){newThread(runnable).start();}mRunOnFirstFix.clear();super.onLocationChanged(location);}protectedvoiddrawMyLocation(Canvascanvas,MapViewmapView,finalLocationmLocation,GeoPointpoint,longtime){Projectionpj=mapView.getProjection();if(mLocation!=null){mMapCoords=pj.toPixels(point,null);finalfloatradius=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);}}}如果不清楚啊,可以到我群里討論lookatmyname

Ⅲ android 怎麼調用高德地圖

地圖類型區分功能。
主要有2D,3D,以及衛星地圖三種類型的地圖可以選擇。

衛星地圖在放大後,適合短距離找路,較為直觀。
2D3D則適合長距離把握地理位置。

大拇指在手機屏幕上旋轉可以改變方向,可以調整你前進的方向為手機的方向。

找出最短路線。
在搜索框輸入起始地和目的地,自動生成路線圖。

各類服務查找功能。
在出行處可以找到加油、停車、吃飯、公交、洗車等等服務。

探索街景。
注意圖的各個位置有遠景、全景等小標志。
點開可以看到三維的圖,如身臨其境般。

這是全景圖下的截屏,在手機上看是連續的三維空間的圖。

高品質的地圖適宜在wifi強的條件下使用。
離線地圖下載為我們解決了這一弊端,下載後使用更迅捷。

Ⅳ android高德地圖怎麼由城市名稱設置位置

第一步,我們需要下載SDK
第二步,解壓後,將jar包放進libs文件夾中,並加入環境變數中。

第三步,在AndroidManifest.xml文件中配置許可權:
<!--用於進行網路定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!--用於訪問GPS定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--用於獲取運營商信息,用於支持提供運營商信息相關的介面-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--用於訪問wifi網路信息,wifi信息會用於進行網路定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!--用於獲取wifi的獲取許可權,wifi信息會用來進行網路定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!--用於訪問網路,網路定位需要上網-->
<uses-permission android:name="android.permission.INTERNET"/>
<!--用於讀取手機當前的狀態-->

Ⅳ android手機 高德導航地圖放哪個目錄下

1、在自己的手機桌面上,找到高德地圖並點擊進入。

Ⅵ android使用高德定位sdk獲取的城市名稱怎樣讓其他的界面進行調用

第一步,我們需要下載SDK
第二步,解壓後,將jar包放進libs文件夾中,並加入環境變數中。

第三步,在AndroidManifest.xml文件中配置許可權:
<!--用於進行網路定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!--用於訪問GPS定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--用於獲取運營商信息,用於支持提供運營商信息相關的介面-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--用於訪問wifi網路信息,wifi信息會用於進行網路定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!--用於獲取wifi的獲取許可權,wifi信息會用來進行網路定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!--用於訪問網路,網路定位需要上網-->
<uses-permission android:name="android.permission.INTERNET"/>
<!--用於讀取手機當前的狀態-->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!--用於寫入緩存數據到擴展存儲卡-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--用於申請調用A-GPS模塊-->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

並在application標簽中添加:
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="你申請的key" />
<service android:name="com.amap.api.location.APSService" />

第四步,測試代碼:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;

public class MainActivity extends AppCompatActivity {
//聲明AMapLocationClient類對象
public AMapLocationClient mLocationClient = null;
//聲明定位回調監聽器
public AMapLocationListener mLocationListener = new MyAMapLocationListener();
//聲明AMapLocationClientOption對象
public AMapLocationClientOption mLocationOption = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}

private void init() {
//初始化定位
mLocationClient = new AMapLocationClient(getApplicationContext());
//設置定位回調監聽
mLocationClient.setLocationListener(mLocationListener);
//初始化AMapLocationClientOption對象
mLocationOption = new AMapLocationClientOption();
//設置定位模式為AMapLocationMode.Hight_Accuracy,高精度模式。
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//獲取一次定位結果:
//該方法默認為false。
mLocationOption.setOnceLocation(false);

//獲取最近3s內精度最高的一次定位結果:
//設置setOnceLocationLatest(boolean b)介面為true,啟動定位時SDK會返回最近3s內精度最高的一次定位結果。如果設置其為true,setOnceLocation(boolean b)介面也會被設置為true,反之不會,默認為false。
mLocationOption.setOnceLocationLatest(true);
//設置是否返回地址信息(默認返回地址信息)
mLocationOption.setNeedAddress(true);
//設置是否允許模擬位置,默認為false,不允許模擬位置
mLocationOption.setMockEnable(false);
//關閉緩存機制
mLocationOption.setLocationCacheEnable(false);
//給定位客戶端對象設置定位參數
mLocationClient.setLocationOption(mLocationOption);
//啟動定位
mLocationClient.startLocation();

}

private class MyAMapLocationListener implements AMapLocationListener {

@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
Log.e("位置:", aMapLocation.getAddress());
} else {
//定位失敗時,可通過ErrCode(錯誤碼)信息來確定失敗的原因,errInfo是錯誤信息,詳見錯誤碼表。
Log.e("AmapError", "location Error, ErrCode:"
+ aMapLocation.getErrorCode() + ", errInfo:"
+ aMapLocation.getErrorInfo());
}
}
}
}
}

Ⅶ android中用高德地圖通過地址獲取經緯度

直接在gps工程測試模式下定位,就可以得到經緯度還有你所在地的高度。你也可以使用凱立德這類的導航軟體。

Ⅷ android studio高德地圖載入離線地圖如何做

一、注冊開發者賬號,新建新Key。
二、首先根據高德地圖開發者獲取key。
androidstudio獲取SHA1方法:打開androidstudio的Termina(alt+F12),輸入命令:keytool -v -list -keystore keystore文件路徑(默認路徑 C:\Users\用戶名\.android debug.keystore),默認密碼:android,即可獲取SHA1。
PackageName為app中build。gradle中的applicationId。
三、打開AndroidStudio-->Build-->Generate Signed APK-->Create new...,創建新的key,按照圖示創建即可,要記下Alias的名字和密碼,然後選擇第V2-->finish即可。
四、新建工程,將下載的SDK的jar包復制到工程libs下,並add as library(復制→粘貼到文件夾下即可)。
五、3D地圖需要添加so庫:在main目錄下創建jniLibs,將下載的so庫文件拷貝到這個目錄下。

Ⅸ 高德地圖,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 高德地圖的開發 移動地圖流暢性

這里不得不說下個人情況,此項目是他人開發,而開發人員已經不在公司,bug轉發給我了。自己之前也沒怎麼使用過高德,主要使用的是谷歌地圖和mapbox。在修改這個bug的時候,思緒會受谷歌api一些影響,因為一直覺得他們的api都差不多。現在我打開自己的頁面,然後拖動marker,拖動結束我會列印一下經緯度,然後把這個經緯度復制下來,並在高德的官方地圖上去搜索獲取到的這個經緯度。結果確實一直都是有偏差的,而且還偏差值每次都不同。

熱點內容
單片機android 發布:2024-09-20 09:07:24 瀏覽:760
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:661
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:309
子彈演算法 發布:2024-09-20 08:41:55 瀏覽:286
手機版網易我的世界伺服器推薦 發布:2024-09-20 08:41:52 瀏覽:815
安卓x7怎麼邊打游戲邊看視頻 發布:2024-09-20 08:41:52 瀏覽:160
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:91
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:505
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:655
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:479