【问题标题】:get map from geoserver to argis sdk android从geoserver获取地图到argis sdk android
【发布时间】:2015-07-13 15:11:37
【问题描述】:

我无法在 Android Studio 1.1.0 中使用 argis SDK 从 geoserver 2.7 获取地图到我的 Android 应用程序我尝试通过 WMS(Web 地图服务)将地图获取到我的 android 应用程序,她的代码如下

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import com.esri.android.map.MapView;
    import com.esri.android.map.ogc.WMSLayer;

    public class MainActivity extends Activity {
        MapView mMapView;
        WMSLayer wmsLayer;
        String wmsURL;

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

            // after the content of this activity is set
            // the map can be accessed from the layout
            mMapView = (MapView)findViewById(R.id.map);

            // set up the wms url
            wmsURL ="http://10.1.1.100:8090/geoserver/cyobjet/wms?service=WMS" +
                    "&version=1.1.0" +
                    "&request=GetMap" +
                    "&layers=cyobjet:object" +
                    "&styles=" +
                    "&bbox=-20.8250007629395,-9.94999980926514,4185.8251953125,1999.94995117188" +
                    "&width=690&height=330" +
                    "&srs=EPSG:900913" +
                    "&format=image%2Fpng";
            wmsLayer = new WMSLayer(wmsURL);
            wmsLayer.setImageFormat("image/png");
            // available layers
            String[] visibleLayers = {"cyobject:object"};
            wmsLayer.setVisibleLayer(visibleLayers);
            wmsLayer.setOpacity(0.5f);
            mMapView.addLayer(wmsLayer);

            // Set the Esri logo to be visible, and enable map to wrap around date line.
            mMapView.setEsriLogoVisible(true);
            mMapView.enableWrapAround(true);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {

            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();

            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }

            return super.onOptionsItemSelected(item);
        }
    }

和我的 Androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pfe.loungou.map" >
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

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

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

</manifest>

和我的布局在我的 android APP 中查看 MAP

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <!-- MapView -->
    <com.esri.android.map.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

</RelativeLayout>

我正在我的安卓手机中测试应用程序,当我打开它时出现黑屏 PS:当我在手机浏览器中获得下面的链接时,我得到了 MAP,我认为我的地理服务器正在运行并且我的 Android 代码存在问题,所以希望对我有所帮助;)

【问题讨论】:

  • PS:我的安卓APP使用arcGIS SDK

标签: java android arcgis geoserver wms


【解决方案1】:

通过从wmsURL 中删除参数,我使地图正常工作。这是修改后的代码:

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.MapView;
import com.esri.android.map.ogc.WMSLayer;


public class MainActivity extends Activity {
MapView mMapView;
WMSLayer wmsLayer;
String wmsURL;

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

    // after the content of this activity is set
    // the map can be accessed from the layout
    mMapView = (MapView)findViewById(R.id.map);

    wmsURL = "http://10.1.1.100:8090/geoserver/cyobjet/wms";
    wmsLayer = new WMSLayer(wmsURL);
    wmsLayer.setImageFormat("image/png");
    // available layers
    String[] visibleLayers = {"cyobjet:object"};
    wmsLayer.setVisibleLayer(visibleLayers);
    wmsLayer.setOpacity(0.5f);
    mMapView.addLayer(wmsLayer);


    mMapView.setEsriLogoVisible(false);
    mMapView.enableWrapAround(true);
    }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多