supermap andiord开发地图加载不出来
ADT Bundle开发,Genymotion 模拟器,利用SuperMap iMobile做了一个最简单的地图显示,代码如下:
activity_main中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main">
<RelativeLayout
android:gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.supermap.mapping.MapView
android:id = "@+id/Map_view"
android:layout_width="fill_parent"
android:layout_height = "fill_parent">
</com.supermap.mapping.MapView>
<ZoomControls
android:id="@+id/zoomControls"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>
MainActivity中:
package com.example.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ZoomControls;
import com.supermap.data.Environment;
import com.supermap.data.Workspace;
import com.supermap.data.WorkspaceConnectionInfo;
import com.supermap.data.WorkspaceType;
import com.supermap.mapping.MapControl;
import com.supermap.mapping.MapView;
public class MainActivity extends Activity {
private MapControl m_mapControl = null;
private Workspace m_workspace;
private MapView m_mapView;
private ZoomControls m_zoom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String rootPath=android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
Environment.setLicensePath(rootPath+"/SuperMap/license/");
Environment.setTemporaryPath(rootPath+"/SuperMap/temp/");
Environment.setWebCacheDirectory(rootPath+"/SuperMap/WebCache/");
Environment.initialization(this);
setContentView(R.layout.activity_main);
m_workspace=new Workspace();
WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
info.setServer(rootPath+"/SampleData/World.smwu");
info.setType(WorkspaceType.SMWU);
m_workspace.open(info);
m_mapView=(MapView)findViewById(R.id.Map_view);
m_mapControl=m_mapView.getMapControl();
m_mapControl.getMap().setWorkspace(m_workspace);
String mapName =m_workspace.getMaps().get(1);
m_mapControl.getMap().open(mapName);
m_zoom = (ZoomControls)findViewById(R.id.zoomControls);
m_mapView = (MapView)findViewById(R.id.Map_view);
m_zoom.setIsZoomInEnabled(true);
m_zoom.setIsZoomOutEnabled(true);
//放大按钮
m_zoom.setOnZoomInClickListener(new OnClickListener(){
public void onClick(View v) {
m_mapControl.getMap().zoom(2);
m_mapControl.getMap().refresh();
}
});
//缩小按钮
m_zoom.setOnZoomOutClickListener(new OnClickListener(){
public void onClick(View v) {
m_mapControl.getMap().zoom(0.5);
m_mapControl.getMap().refresh();
}
});
m_mapControl.getMap().refresh();
}
}
运行时程序可以打开,但是出现黑屏,地图加载不出来