最新基于高德地图的android进阶开发(5)地图的基本操作、事件监听、用户UI、图层选择等

本文介绍了高德地图在Android开发中的高级应用,包括地图的初次加载,camera视图的移动、动画操作,以及单击、长按、触摸等事件的监听。通过具体的布局文件和核心代码示例,详细解析了每个功能的实现过程。
摘要由CSDN通过智能技术生成

1.高德地图的基本操作:最简单的莫过于第一次加载地图

布局文件:basic_map.xml,在下面的操作中,未作特别说明都采用此布局文件。

<?xml version="1.0" encoding="utf-8"?>
<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" >
</com.amap.api.maps.MapView>

基本操作:第一次加载地图。

package com.dragon.arnav.basicFuction.basic;

import android.app.Activity;
import android.os.Bundle;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.dragon.arnav.R;

/**
 * This file created by dragon on 2016/7/28 21:26,belong to com.dragon.arnav.basicFuction.basic .
 */
public class basicMap extends Activity {
   
    private MapView mapView;
    private AMap aMap;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
//采用这种方式或是下面注视的动态加载都是可以的
        setContentView(R.layout.basic_map);
        mapView = (MapView) findViewById(R.id.map);
//        mapView = new MapView(this);
//        setContentView(mapView);
        mapView.onCreate(savedInstanceState);
        init();
    }
    private void init(){
        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 onDestroy(){
        super.onDestroy();
        mapView.onDestroy();
    }
    @Override
    public void onSaveInstanceState(Bundle outState){
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }
}

2.camera视图实战,包括移动、动画视图、停止等,来自官方的demo

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <Button
                android:id="@+id/stop_animation"
                android:layout_width="40dip"
                android:layout_height="40dip"
                android:text="@string/stop_animation" />

            <ToggleButton
                android:id="@+id/animate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:textOff="@string/animate"
                android:textOn="@string/animate" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation&
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值