初識高徳地図API


<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">  MapView   </span>

一、レイアウトファイルの導入
<com.amap.api.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
 
 

二、在Activity中的基本程序代码(高德官方demo)

public class BasicMapActivity extends Activity {
    private MapView mapView;
    private AMap aMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.basicmap_activity);
        mapView = (MapView) findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);//     
        if (aMap == null) {
            aMap = mapView.getMap();
        }
    }

    /**
     *       
     */
    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    /**
     *       
     */
    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }
    
    /**
     *       
     */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    /**
     *       
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }
}

三、地図操作
1,表示領域の変更:CameraUpdateクラスの使用
aMap.moveCamera(update);//     
aMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(Constants.ZHONGGUANCUN,18, 0, 30)),1000, callback);//      CameraUpdate,    CameraPosition     ,          ,                 
(CameraPostion  :CameraPosition LUJIAZUI = new CameraPosition.Builder().target(Constants.SHANGHAI).zoom(18).bearing(0).tilt(30).build();
//target LatLng  ,zoom     ,bearing          ,      ,     0 ,tilt           ,      。)

2,拡大縮小地図:やはりCameraUpdateクラスを使う
aMap.animateCamera(CameraUpdateFactory.zoomIn(),1000, callback);
aMap.animateCamera(CameraUpdateFactory.zoomOut(),1000, callback);

3、地図クリックまたはコールバックリスニングインターフェースの移動を設定する
aMap.setOnMapClickListener(this);//  amap           
aMap.setOnMapLongClickListener(this);//  amap           
aMap.setOnCameraChangeListener(this);//  amap           

4、地図モードを設定する:
aMap.setMapType(AMap.MAP_TYPE_NORMAL);//       

5、交通状況を表示する:
aMap.setTrafficEnabled(false);//         

6、地図表示に関する属性を設定する
mUiSettings = aMap.getUiSettings();
mUiSettings.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT);//     logo      
mUiSettings.setZoomControlsEnabled(false); //        
mUiSettings.setCompassEnabled(false); //       
mUiSettings.setMyLocationButtonEnabled(true); //            
(     true ,          
     aMap.setMyLocationEnabled(true);//              
     aMap.setLocationSource(this);//       
        
     @Override
     public void activate(OnLocationChangedListener listener) {
         mListener = listener;
         if (mAMapLocationManager == null) {
            mAMapLocationManager = LocationManagerProxy.getInstance(getActivity());
            mAMapLocationManager.setGpsEnable(true);
            mAMapLocationManager.requestLocationUpdates(LocationProviderProxy.AMapNetwork, 5000, 10, this);
        }
    }

    @Override
    public void deactivate() {
        mListener = null;
        if (mAMapLocationManager != null) {
            mAMapLocationManager.removeUpdates(this);
        }
        mAMapLocationManager = null;
    }
)

mUiSettings.setScrollGesturesEnabled(false);//      
mUiSettings.setZoomGesturesEnabled(true);//        
mUiSettings.setTiltGesturesEnabled(true);//        
mUiSettings.setRotateGesturesEnabled(true);//        

7,  Markerセクション:
(1)
aMap.setOnMarkerDragListener(this);//   marker        
aMap.setOnMapLoadedListener(this);//   amap         
aMap.setOnMarkerClickListener(this);//     marker     
aMap.setOnInfoWindowClickListener(this);//     infoWindow     
aMap.setInfoWindowAdapter(this);//      InfoWindow  ,             view

(2)
MarkerOptions markerOptions=new MarkerOptions();
markerOptions.position(someLatlng);
markerOptions.title("someTitle");
markerOptions.snippet("SomeSnippet");
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.xx);
markerOptions..perspective(true).draggable(true);
Marker aMarker= aMap.addMarker(markerOptions);
//Marker  aMap addMarker    ,addMarker    MarkerOptions,markerOptions    position     ,title snippet infowindow infocontent      title snippet  ,icon    BitmapDescriptorFactory.fromXXX       BitmapDescriptorFactory.defaultMarker()    ,   view  ,  view             ,         ,perspective       (2.1.0    ),draggable      

aMarker.showInfoWindow();//     marker infowinfow

(3)
aMap.clear();//        Marker