<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Android_百度地圖_獲得個(gè)人的位置并在地圖上展現(xiàn)

      本頁面主要講述為單個(gè)模塊抽取出來的使用方法,如果要多個(gè)模塊整合在一起可以使用百度Demo里面extends MapActivity,下面為個(gè)人位置的獲取并在地圖展現(xiàn)的事項(xiàng)

       

      1.在配置文件中添加百度地圖使用的一些相關(guān)權(quán)限(請(qǐng)求網(wǎng)絡(luò)等)

      1   <!-- 添加百度地圖權(quán)限 -->
      2  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
      3     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
      4     <uses-permission android:name="android.permission.INTERNET"></uses-permission>
      5     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
      6     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>  
      7     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> 
      8     <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
      9     <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

      2.在配置文件中添加對(duì)屏幕的支持

      1  <!-- 添加對(duì)屏幕的支持 -->
      2     <supports-screens android:largeScreens="true"
      3         android:normalScreens="false" android:smallScreens="true"
      4         android:resizeable="true" android:anyDensity="true"/>

      3.在layout布局文件中添加顯示地圖的控件

       1 <?xml version="1.0" encoding="utf-8"?>
       2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       3     android:layout_width="fill_parent"
       4     android:layout_height="fill_parent"
       5     android:orientation="vertical" >
       6 <!-- 添加顯示地圖的demo -->
       7     <com.baidu.mapapi.MapView android:id="@+id/bmapView"
       8     android:layout_width="fill_parent" android:layout_height="fill_parent" 
       9     android:clickable="true"     
      10 />
      11 
      12 </LinearLayout>

      4.寫一個(gè)Activity繼承MapActivity以下為顯示個(gè)人坐標(biāo)以及添加多個(gè)覆蓋物的代碼

        1 package com.novaloncn.user.activity.map;
        2 
        3 import java.nio.channels.FileChannel.MapMode;
        4 import java.util.ArrayList;
        5 import java.util.List;
        6 
        7 import android.content.Intent;
        8 import android.graphics.drawable.Drawable;
        9 import android.location.Location;
       10 import android.os.Bundle;
       11 import android.util.Log;
       12 import android.view.View;
       13 import android.widget.Toast;
       14 
       15 import com.baidu.mapapi.BMapManager;
       16 import com.baidu.mapapi.GeoPoint;
       17 import com.baidu.mapapi.ItemizedOverlay;
       18 import com.baidu.mapapi.LocationListener;
       19 import com.baidu.mapapi.MKGeneralListener;
       20 import com.baidu.mapapi.MapActivity;
       21 import com.baidu.mapapi.MapController;
       22 import com.baidu.mapapi.MapView;
       23 import com.baidu.mapapi.MyLocationOverlay;
       24 import com.baidu.mapapi.OverlayItem;
       25 import com.novaloncn.user.R;
       26 import com.novaloncn.user.activity.ExChange_Map;
       27 
       28 
       29 public class Android_BaiduMap_test2 extends MapActivity{
       30 
       31     //添加百度地圖的相關(guān)控件
       32     private MapView mapView;
       33     private BMapManager bMapManager;//加載地圖的引擎
       34     //百度地圖的key
       35     private String keyString="38337A32108C7597D84A9F7E14C1CB6E9844B63A";
       36     //在百度地圖上添加一些控件,比如是放大或者縮小的控件
       37     private MapController mapController;
       38     //onResume時(shí)注冊(cè)此listener,onPause時(shí)需要Remove
       39     private LocationListener mLocationListener=null;//
       40     private MyLocationOverlay mLocationOverlay = null;    //定位圖層
       41     
       42     @Override
       43     protected void onCreate(Bundle savedInstanceState) {
       44         // TODO Auto-generated method stub
       45         super.onCreate(savedInstanceState);
       46         setContentView(R.layout.baidumap);
       47         
       48         mapView=(MapView) this.findViewById(R.id.bmapView);
       49         bMapManager=new BMapManager(Android_BaiduMap_test2.this);
       50         
       51         
       52          bMapManager=new BMapManager(Android_BaiduMap_test2.this);
       53             //必須加載key
       54             bMapManager.init(keyString, new MKGeneralListener() {
       55                 
       56                 public void onGetPermissionState(int arg0) {
       57                     // TODO Auto-generated method stub
       58                     if(arg0==300){
       59                         Toast.makeText(Android_BaiduMap_test2.this, "輸入的Key有錯(cuò)!請(qǐng)核實(shí)", 1).show();
       60                     }
       61                 }
       62                 
       63                 public void onGetNetworkState(int arg0) {
       64                     // TODO Auto-generated method stub
       65                     
       66                 }
       67             });
       68             
       69             initMapActivity(bMapManager);
       70             mapView.setBuiltInZoomControls(true);//表示可以設(shè)置縮放功能
       71            
       72             mapController=mapView.getController();
       73             mapController.setZoom(14);
       74             
       75             
       76 //            //需要定義一個(gè)經(jīng)緯度:上海張江
       77 //            GeoPoint geoPoint=new GeoPoint((int)(31.514560*1E6), (int)(121.935551*1E6));
       78 //            
       79 //            mapController.setCenter(geoPoint);//設(shè)置一個(gè)中心點(diǎn)
       80 //            
       81 //            mapController.setZoom(15);//設(shè)置縮放級(jí)別是12個(gè)級(jí)別
       82 //            
       83 //            mapView.setBuiltInZoomControls(true);
       84 //            //設(shè)置在縮放動(dòng)畫過程中也顯示overlay,默認(rèn)為不繪制
       85 //            mapView.setDrawOverlayWhenZooming(true);
       86 //         // 添加定位圖層
       87 //            mLocationOverlay = new MyLocationOverlay(this, mapView);
       88 //            mapView.getOverlays().add(mLocationOverlay);
       89             
       90             //顯示交通地圖
       91 //            mapView.setTraffic(true);
       92             //顯示衛(wèi)星地圖
       93 //            mapView.setSatellite(true);
       94             
       95          // 添加定位圖層
       96             mLocationOverlay = new MyLocationOverlay(this, mapView);
       97             mapView.getOverlays().add(mLocationOverlay);
       98             
       99             // 注冊(cè)定位事件
      100             mLocationListener = new LocationListener(){
      101 
      102                 
      103                 public void onLocationChanged(Location location) {
      104                     if (location != null){
      105                         GeoPoint pt = new GeoPoint((int)(location.getLatitude()*1e6),
      106                                 (int)(location.getLongitude()*1e6));
      107                         mapView.getController().animateTo(pt);
      108                     }
      109                 }
      110             };
      111             
      112             
      113             
      114             
      115         }
      116         public void daohang(View v){
      117             Intent intent=new Intent(Android_BaiduMap_test2.this,ExChange_Map.class);
      118             finish();
      119             startActivity(intent);
      120         }
      121         public void myGps(View v){
      122             Toast.makeText(Android_BaiduMap_test2.this, "GPS唄點(diǎn)擊了", 0).show();
      123             
      124             
      125             
      126             mLocationListener=new LocationListener() {
      127                 
      128                 public void onLocationChanged(Location location) {
      129                     if(location!=null){
      130                         GeoPoint pt=new GeoPoint((int)(location.getLatitude()*1e6),
      131                                 (int)(location.getLongitude()*1e6));
      132                         mapView.getController().animateTo(pt);
      133 //                        mapController.setZoom(4);
      134                     }
      135                 }
      136             };
      137             bMapManager.getLocationManager().requestLocationUpdates(mLocationListener);
      138                
      139             mLocationOverlay.enableMyLocation();
      140             mapController.zoomIn();
      141             
      142             
      143         }
      144         public void environment(View v){
      145             Toast.makeText(Android_BaiduMap_test2.this, "我被點(diǎn)擊了", 0).show();
      146              Drawable drawable=getResources().getDrawable(R.drawable.iconmarka);
      147              
      148              MyOverLayItem myOverLayItem = new MyOverLayItem(drawable);
      149             mapView.getOverlays().add(myOverLayItem);
      150 //            myOverLayItem.populate();//刷新地圖的功能
      151 //            bMapManager.notifyAll();
      152             mapController.zoomIn();
      153         }
      154         
      155          public class MyOverLayItem extends ItemizedOverlay<OverlayItem>{
      156 
      157                 private List<OverlayItem> list=new ArrayList<OverlayItem>();
      158                 //定義一組坐標(biāo),都是以double類型定義
      159 //                   (31.214546*1E6), (int)(121.635574*1E6));
      160                 private double mLat1=31.15443;//表示緯度
      161                 private double mLonl=121.57428;//表示經(jīng)度
      162                 
      163                 private double mLat2=31.23443;//表示緯度
      164                 private double mLon2=121.657428;//表示經(jīng)度
      165                 
      166                 private double mLat3=31.22777;//表示緯度
      167                 private double mLon3=121.59000;//表示經(jīng)度
      168                 
      169                 private double mLat4=31.22477;//表示緯度
      170                 private double mLon4=121.6300;//表示經(jīng)度
      171                 
      172                 private double mLat5=31.21977;//表示緯度
      173                 private double mLon5=121.634000;//表示經(jīng)度
      174                 
      175                 
      176                 
      177                 //用于在地圖上標(biāo)識(shí)坐標(biāo),用一個(gè)圖片標(biāo)注
      178                 public MyOverLayItem(Drawable arg0) {
      179                     super(arg0);
      180                     // TODO Auto-generated constructor stub
      181                     //第一組數(shù)據(jù)在地圖上的標(biāo)注點(diǎn)
      182                     GeoPoint geoPoint1=new GeoPoint((int)(mLat1*1E6), (int)(mLonl*1E6));
      183                     //第二組數(shù)據(jù)在地圖上的標(biāo)注點(diǎn)
      184                     GeoPoint geoPoint2=new GeoPoint((int)(mLat2*1E6), (int)(mLon2*1E6));
      185                     //第三組數(shù)據(jù)在地圖上的標(biāo)注點(diǎn)
      186                     GeoPoint geoPoint3=new GeoPoint((int)(mLat3*1E6), (int)(mLon3*1E6));
      187                     //第四組數(shù)據(jù)在地圖上的標(biāo)注點(diǎn)
      188                     GeoPoint geoPoint4=new GeoPoint((int)(mLat4*1E6), (int)(mLon4*1E6));
      189                 
      190                     //第五組數(shù)據(jù)在地圖上的標(biāo)注點(diǎn)
      191                     GeoPoint geoPoint5=new GeoPoint((int)(mLat5*1E6), (int)(mLon5*1E6));
      192                 
      193                     list.add(new OverlayItem(geoPoint1, "Ponit1", "Point1"));
      194                     list.add(new OverlayItem(geoPoint2, "Ponit2", "Point2"));
      195                     list.add(new OverlayItem(geoPoint3, "Ponit3", "Point3"));
      196                     list.add(new OverlayItem(geoPoint4, "Ponit4", "位于盛夏路,廣蘭路"));
      197                     list.add(new OverlayItem(geoPoint5, "Ponit5", "位與丹桂路,龍東花園"));
      198                     populate();//刷新地圖的功能
      199                     
      200                 }
      201                 
      202                 //返回指定的list集合中每一個(gè)坐標(biāo)
      203                 @Override
      204                 protected OverlayItem createItem(int arg0) {
      205                     // TODO Auto-generated method stub
      206                     return list.get(arg0);
      207                 }
      208 
      209                 @Override
      210                 public int size() {
      211                     // TODO Auto-generated method stub
      212                     return list.size();
      213                 }
      214                 @Override
      215                 public boolean onTap(int i) {
      216                     // TODO Auto-generated method stub
      217                         Log.e("int-------------", i+"");
      218                         if(i==1){
      219 //                        Intent intent=new Intent(Android_BaiduMap_test2.this,Map2Activity.class);
      220 //                        startActivity(intent);
      221                     }else{
      222                         Toast.makeText(Android_BaiduMap_test2.this, list.get(i).getSnippet(), 1).show();
      223                         
      224                     }
      225                     
      226                     return true;
      227                 }
      228                 
      229             }
      230         @Override
      231         protected void onDestroy() {
      232             // TODO Auto-generated method stub
      233             super.onDestroy();
      234             if(bMapManager!=null){
      235                 bMapManager.destroy();
      236                 bMapManager=null;
      237             }
      238                 
      239         }
      240         @Override
      241         protected void onResume() {
      242             // TODO Auto-generated method stub
      243             super.onResume();
      244             if(bMapManager!=null){
      245                 // 注冊(cè)定位事件,定位后將地圖移動(dòng)到定位點(diǎn)
      246                 bMapManager.getLocationManager().requestLocationUpdates(mLocationListener);
      247                 mLocationOverlay.enableMyLocation();
      248                 mLocationOverlay.enableCompass(); // 打開指南針
      249                 bMapManager.start();
      250             }
      251         }
      252         @Override
      253         protected void onPause() {
      254             // TODO Auto-generated method stub
      255             super.onPause();
      256             if(bMapManager!=null){
      257                 bMapManager.getLocationManager().removeUpdates(mLocationListener);
      258                 mLocationOverlay.disableMyLocation();
      259                 mLocationOverlay.disableCompass(); // 關(guān)閉指南針
      260                 bMapManager.stop();
      261                 
      262             }
      263         }
      264         @Override
      265         protected boolean isRouteDisplayed() {
      266             // TODO Auto-generated method stub
      267             return false;
      268         }
      269     }

      一定要記住 在onPause onDestroy中注銷map

      posted @ 2013-01-24 09:27  王世楨  閱讀(783)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 国产精品日韩av一区二区| 国产精品十八禁在线观看| 中文字幕精品无码一区二区三区| 97在线碰| 色偷偷偷久久伊人大杳蕉| 国产蜜臀久久av一区二区| 免费a级黄毛片| 亚洲国产超清无码专区| 欧美一本大道香蕉综合视频| 国产精品无码无需播放器| 亚洲18禁一区二区三区| 国产精品一区二区三区三级| 激情综合色区网激情五月| 亚洲欧美人成人综合在线播放 | 亚洲av伦理一区二区| 国模雨珍浓密毛大尺度150p| 99精品国产中文字幕| 日本熟妇浓毛| 永久免费精品性爱网站| 亚洲乱色一区二区三区丝袜| 日韩精品一区二区午夜成人版| 伊人色综合一区二区三区| 彰武县| 老色99久久九九爱精品| 亚洲精品无码日韩国产不卡av| 日本免费一区二区三区久久| 国产亚洲欧洲AⅤ综合一区| 亚洲日韩乱码一区二区三区四区| 墨江| 一区二区三区国产亚洲网站| 久久精品国产亚洲AV成人毛片| 一 级做人爱全视频在线看| 亚洲成av一区二区三区| 视频一区二区不中文字幕| 最新精品国偷自产在线美女足| 国产成人综合网亚洲第一| 久久精品国产字幕高潮| 超碰伊人久久大香线蕉综合| 久久精品国产色蜜蜜麻豆| 国产精品无卡毛片视频| 亚洲第一精品一二三区|