我无法使用 Android studio 1.1.0 中的 argis SDK 将 map 从 geoserver 2.7 获取到我的 Android 应用程序,我尝试通过 WMS(网络 map 服务)将 map 获取到我的 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 应用程序中查看 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>
我正在我的 Android 手机中测试该应用程序,当我打开它时,我得到黑屏 PS:当我在手机浏览器中看到下面的链接时,我得到了 map ,我认为我的地理服务器正在运行,并且我的 Android 代码有问题,所以希望能帮助我;)
最佳答案
通过从 wmsURL
中删除参数,我使 map 正常工作。修改后的代码如下:
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);
}
}
关于java - 从geoserver获取 map 到argis sdk android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30026645/