arcgis for android(二)显示二维地图

1、上一节讲了 arcgis for android 入门与提高(一)配置环境https://blog.csdn.net/HB_Programmer/article/details/119967868,接下来看看如何显示二维地图。

2、基于Android Studio,我们打开AndroidManifest.xml,添加网络权限和二维控件支持

<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

3、在activity_main.xml新建MapView

<com.esri.arcgisruntime.mapping.view.MapView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mapview"/>

4、导入包

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;

5、核心代码: 

ArcGISRuntimeEnvironment.setApiKey("在dashboard创建的一个很长的key");
mMapView = findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
mMapView.setMap(map);
mMapView.setViewpoint(new Viewpoint(34.056295, -117.195800, 10000));
@Override
protected void onPause() {
  mMapView.pause();
  super.onPause();
}

@Override
protected void onResume() {
  super.onResume();
  mMapView.resume();
}

@Override
protected void onDestroy() {
  mMapView.dispose();
  super.onDestroy();
}

6、完整代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidgistest">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AndroidGISTest">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

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

    <com.esri.arcgisruntime.mapping.view.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/mapview"/>

</LinearLayout>
package com.example.androidgistest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;

public class MainActivity extends AppCompatActivity {

    MapView mMapView;

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

        ArcGISRuntimeEnvironment.setApiKey("");
        mMapView = findViewById(R.id.mapview);
        mMapView.setAttributionTextVisible(false);//去logo

        ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
        mMapView.setMap(map);
        mMapView.setViewpoint(new Viewpoint(34.056295, -117.195800, 10000));

    }

    @Override
    protected void onPause() {
        mMapView.pause();
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.resume();
    }

    @Override
    protected void onDestroy() {
        mMapView.dispose();
        super.onDestroy();
    }
}

7、效果

8、下一节讲解 arcgis for android 入门与提高(三)显示三维场景arcgis for android 入门与提高(三)显示三维场景_郝大大的博客-CSDN博客

欢迎订阅专栏!

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值