1. 程式人生 > >Android定位&地圖&導航——基於百度地圖移動獲取位置和自動定位

Android定位&地圖&導航——基於百度地圖移動獲取位置和自動定位

public class MainActivity extends Activity {
    public MyApplication app;
    static MapView mMapView = null;
    public MKMapViewListener mMapListener = null;
    MyLocationOverlay myLocationOverlay = null;
    // 定位相關
    LocationClient mLocClient;
    public NotifyLister mNotifyer = null;
    
public MyLocationListenner myListener = new MyLocationListenner(); LocationData locData = null; private MapController mMapController = null; static MKSearch mkSerach; Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { Toast.makeText(MainActivity.
this, "msg:" + msg.what, Toast.LENGTH_SHORT).show(); }; }; static TextView showAddr; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); showAddr
= (TextView) findViewById(R.id.showAddr); MyIcon mi = new MyIcon(this); //在螢幕中心點新增接我圖示 getWindow().addContentView( mi, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); MyIcon2 m2 = new MyIcon2(this); getWindow().addContentView( m2, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mMapView = (MapView) findViewById(R.id.bmapsView); mMapController = mMapView.getController(); initMapView(); app = MyApplication.getInstance(); mLocClient = new LocationClient(this); mLocClient.registerLocationListener(myListener); //搜尋初始化 mkSerach = new MKSearch(); mkSerach.init(app.mBMapManager, new MKSearchListener() { @Override public void onGetWalkingRouteResult(MKWalkingRouteResult arg0, int arg1) { // TODO Auto-generated method stub } @Override public void onGetTransitRouteResult(MKTransitRouteResult arg0, int arg1) { // TODO Auto-generated method stub } @Override public void onGetSuggestionResult(MKSuggestionResult arg0, int arg1) { // TODO Auto-generated method stub } @Override public void onGetPoiResult(MKPoiResult arg0, int arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onGetPoiDetailSearchResult(int arg0, int arg1) { // TODO Auto-generated method stub } @Override public void onGetDrivingRouteResult(MKDrivingRouteResult arg0, int arg1) { // TODO Auto-generated method stub } @Override public void onGetBusDetailResult(MKBusLineResult arg0, int arg1) { // TODO Auto-generated method stub } @Override public void onGetAddrResult(MKAddrInfo info, int arg1) { showAddr.setText(info.strAddr); } }); //設定地圖相關 LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); option.setCoorType("bd09ll"); option.setScanSpan(300000); mLocClient.setLocOption(option); mLocClient.start(); mMapView.getController().setZoom(16); mMapView.getController().enableClick(true); mMapView.displayZoomControls(true); mMapListener = new MKMapViewListener() { public void onMapMoveFinish() { } public void onClickMapPoi(MapPoi mapPoiInfo) { // TODO Auto-generated method stub String title = ""; if (mapPoiInfo != null) { title = mapPoiInfo.strText; Toast.makeText(MainActivity.this, title, Toast.LENGTH_SHORT) .show(); } } }; mMapView.regMapViewListener(MyApplication.getInstance().mBMapManager, mMapListener); myLocationOverlay = new MyLocationOverlay(mMapView); locData = new LocationData(); myLocationOverlay.setData(locData); mMapView.getOverlays().add(myLocationOverlay); myLocationOverlay.enableCompass(); mMapView.refresh(); } private void initMapView() { mMapView.setLongClickable(true); } /** * 監聽函式,又新位置的時候,格式化成字串,輸出到螢幕中 */ public class MyLocationListenner implements BDLocationListener { public void onReceiveLocation(BDLocation location) { if (location == null) return; locData.latitude = location.getLatitude(); locData.longitude = location.getLongitude(); locData.direction = 2.0f; locData.accuracy = location.getRadius(); locData.direction = location.getDerect(); Log.d("loctest", String.format("before: lat: %f lon: %f", location.getLatitude(), location.getLongitude())); myLocationOverlay.setData(locData); mMapView.refresh(); mMapController .animateTo(new GeoPoint((int) (locData.latitude * 1e6), (int) (locData.longitude * 1e6)), mHandler .obtainMessage(1)); } public void onReceivePoi(BDLocation poiLocation) { if (poiLocation == null) { return; } } } public class NotifyLister extends BDNotifyListener { public void onNotify(BDLocation mlocation, float distance) { } } @Override protected void onPause() { mMapView.onPause(); super.onPause(); } @Override protected void onResume() { mMapView.onResume(); super.onResume(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mMapView.onRestoreInstanceState(savedInstanceState); } public static void getPosition(GeoPoint g) { mkSerach.reverseGeocode(g); showAddr.setText("獲取位置中..."); } }

相關推薦

Android定位&地圖&導航——基於地圖移動獲取位置自動定位

public class MainActivity extends Activity { public MyApplication app; static MapView mMapView = null; public MKMapViewListener mMapListen

Android定位&地圖&導航——基於地圖實現的定位功能

public class MyApplication extends Application{ public LocationClient mLocationClient = null; public GeofenceClient mGeofenceClient; publi

Android定位&地圖&導航——基於地圖,實現自定義圖示繪製並點選時彈出泡泡

public class MainActivity extends Activity { private EditText txtAddr; // 定位相關 LocationClient mLocClient; LocationData locData = nul

Android開發-基於地圖API開發仿滴滴出行APP介面的實現

前 言 近年來,由於移動網際網路快速的發展以及基於移動裝置的APP的普及,移動網際網路改變了人們的生活方式。從線上的電子支付到線下的出行,移動網際網路是當今社會人們生活不可或缺的一部分,而線下出行的網約車的出現極大便利了人們的出行,雖然它飽受了很大的爭議,但不可否認的是網約車的出現是

2016基於地圖定位

現在百度改版後有點不習慣,沒辦法,只有自己又去看了一下,比以前的簡單方便多,有時間我會把導航等給做出來,當然了這個程式碼只是對於初學者來的,因為我自己也是初學者,你自己也可以在百度API上去看,試著寫一遍,我這個主要的目的還是因為最近需要我才弄了一個定位的東西提

基於地圖開發網易班車地圖導航展示

col uri type open one 記錄 length () 代碼 來到網易已經不知不覺一兩個月了,最近把原來租的房子出租後,打算重新租一套房子。找到一個好房子不容易,首先考慮交通問題,上下班時間不能耗費太長,網易提供了遍布全城的班車系統,不過說實話,貌似只有文字說

基於地圖SDKElasticsearch GEO查詢的地理圍欄分析系統(3)-前端實現

方便 復制 類型 復制代碼 自動跳轉 rar 窗口 stack delete 轉載自:http://www.cnblogs.com/Auyuer/p/8086975.html MoonLight可視化訂單需求區域分析系統實現功能:   在現實生活中,計算機和互聯網迅速發展,

基於地圖API刪除指定的覆蓋物

引用百度地圖API過程中,想刪除指定的覆蓋物,有很多很多的坑。什麼clearOverlay()方法,直接給我所有覆蓋物都給乾沒了。還有網上介紹的removeOverlay(物件),這種又介紹不清楚,然後自己經過實踐,最終解決了。 直接上圖、上程式碼。 查詢所有地圖的覆蓋物程式碼: /

基於地圖API的WinForm地圖

      大概去年的這個時候,我用VB寫了一個百度地圖的Demo,使用了webBrowser載入本地網頁的方式,只是限於當時的技術,好多功能都沒實現,昨天,我重新對這個程式進行了編寫,這一次我使用的是C#。在正式開始之前,先來解決幾個問題。       一、地圖    

Android程式打包後,地圖key驗證失敗解決辦法

今天在對專案進行打包簽名,通過apk安裝到手機上後,忽然發現百度地圖無法使用了,思前想後,終於找到了原因。 我們在呼叫百度地圖api需要通過SHA1+“,”+包名的方式獲取百度地圖Key,而在專案除錯階段我們一般使用的都是使用Eclipse的除錯簽名,但是當專案真正上線之

基於地圖SDK整合的一些功能

最近開發的專案用到了地圖,並在地圖上顯示某些座標位置的標記圖示,點選圖示來顯示此座標處的一些資訊,之後我從百度地圖卡房平臺下載了百度地圖的SDK和Demo,並結合API總結了一下幾點內容,實現了下面的幾個功能: (1)最基本功能,定位到當前位置 並獲

一個基於地圖的桌面軟體(附工程原始碼)

光陰似箭,日月如梭,恍然間,2013就這樣平平淡淡的過去了。想想工資卡上的餘額,心中不免浮起蛋蛋的憂桑。如果再回到2013。。。。。罷了,青春就是如此,每個人都肆無忌憚的揮霍著,在年華正當之時。或許只有當歲月的烙印狠狠落下的那一刻,我們才會想起那再也回不去的美好年華,那落英

iOS基於地圖的開發(1)——使用者當前位置

首先需要設定mapView的屬性: self.mapView = [[[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] aut

使用瀏覽器自帶定位功能初始化地圖

if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition, showError); // HTML5獲取GPS裝置地理位置資訊 } else { docu

Android開發 用AndroidStudio開發地圖Demo時的經典錯誤230的另一種可能

Authentication Error errorcode: 230 uid: -1 appid -1 msg: APP Scode碼校驗失敗 令人眼紅的字眼,這個神奇的錯誤折騰了我一晚上,一切都是

基於地圖做動態路線打點

// 百度地圖API功能 // 百度地圖獲取容器 var mp = new BMap.Map("allmap"); // 百度地圖定義中心點 mp.centerAndZoom(new BMap.Point(116.3964,39.9093), 15); //

Android Studio地圖開發(地圖

第一步、配置環境 1.申請百度地圖key 首先到百度地圖開放平臺,登入賬號,然後到如下介面 點選“建立應用”,到如下介面,填寫應用名稱,應用型別選擇“Android SDK” 獲取釋出版SHA1和開發版SHA1,連結如下百度提供的獲取SHA1的方法,注

隱藏 google 地圖 Logo 隱藏 地圖 Logo

隱藏 blog col -s container pan event contain first Google 地圖 var isFirstLoad=true; //地圖瓦片加載完成之後的回調 google.maps.event.addListener(map, ‘til

地圖】在地圖上框出邊界線

程式碼: 一、建立地圖 建立地圖物件;設立中心點以及地圖級別。 var map = new BMap.Map("container"); map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 12); 二、新增地圖事件

地圖開發之——地圖鷹眼軌跡管理臺DEMO-v3部署到伺服器上

百度地圖開發官方下載口:https://github.com/baidu-openmap-trace/web-demo-v3 第一:部署準備 搭建NPM和FIS3的環境 1、安裝node.js:https://nodejs.org/en/ 點選版本下載,然後就安裝