我们刚开始在Android与谷歌地图的工作,有一个GeoServer的成立,提供瓷砖,我们想添加在地图上叠加。 到目前为止,我按照一些教程和参考上手。
- 为了得到MyLocation
- 建立在Android WMS
- WMS参考
问题 :当我在我生成的URL getTileUrl
在功能TileProviderFactory
确实返回一个PNG图像时,我设置一个断点和URL复制并粘贴到浏览器中,它不会加载到地图上的叠加Android设备。 有没有错误,从我所看到和阅读后,被抛出这个我不知道是否会有任何因为他们已经表示,正在静音的错误。
我想知道是如果你可以看到在我的代码任何直接的问题或有进行调试,我就能告诉我们,如果应用程序实际上是用我的GeoServer通信检索图像或没有任何建议。 我看了日志上的GeoServer和它好像只是我的浏览器请求正在经历并且它没有收到来自Android的任何请求(这是一个有点难以启齿,因为我们使用的服务器以及其他应用程序)。 Android手机是通过WiFi和细胞连接并启用了GPS。 作为最后的手段我试图改变瓦覆盖用zIndex并将其设置为可见,但这似乎并没有任何区别。
编辑:Android设备是绝对不能用的GeoServer在这一点上通信。
编辑2:可以从网站(如负载静态图像此 )的叠加,发现我正在上测试出一个HTTP请求的URL形成以下情况除外:
W/System.err(10601): java.net.SocketException: The operation timed out
W/System.err(10601): at org.apache.harmony.luni.platform.OSNetworkSystem
.connectStreamWithTimeoutSocketImpl(Native Method)
W/System.err(10601): at org.apache.harmony.luni.net.PlainSocketImpl
.connect(PlainSocketImpl.java:244)
W/System.err(10601): at org.apache.harmony.luni.net.PlainSocketImpl
.connect(PlainSocketImpl.java:533)
W/System.err(10601): at java.net.Socket
.connect(Socket.java:1074)
W/System.err(10601): at org.apache.http.conn.scheme.PlainSocketFactory
.connectSocket(PlainSocketFactory.java:119)
谢谢。
MapTestActivity
public class MapTestActivity extends FragmentActivity
implements LocationListener, LocationSource{
private GoogleMap mMap;
private OnLocationChangedListener mListener;
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_test);
setupLocationManager();
setupMapIfNeeded();
}
private void setupLocationManager() {
this.locationManager =
(LocationManager) getSystemService(LOCATION_SERVICE);
if (locationManager != null) {
boolean gpsIsEnabled = locationManager.isProviderEnabled(
LocationManager.GPS_PROVIDER);
boolean networkIsEnabled = locationManager.isProviderEnabled(
LocationManager.NETWORK_PROVIDER);
if(gpsIsEnabled) {
this.locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 5000L, 10F, this);
}
else if(networkIsEnabled) {
this.locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 5000L, 10F, this);
}
else {
//Show an error dialog that GPS is disabled...
}
}
else {
// Show some generic error dialog because
// something must have gone wrong with location manager.
}
}
private void setupMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
mMap.setLocationSource(this);
}
}
private void setUpMap() {
// TODO Auto-generated method stub
mMap.setMyLocationEnabled(true);
TileProvider geoServerTileProvider = TileProviderFactory
.getGeoServerTileProvider();
TileOverlay geoServerTileOverlay = mMap.addTileOverlay(
new TileOverlayOptions()
.tileProvider(geoServerTileProvider)
.zIndex(10000)
.visible(true));
}
// Non-relevant listener methods removed
}
TileProviderFactory
public class TileProviderFactory {
public static GeoServerTileProvider getGeoServerTileProvider() {
String baseURL = "mytileserver.com";
String version = "1.3.0";
String request = "GetMap";
String format = "image/png";
String srs = "EPSG:900913";
String service = "WMS";
String width = "256";
String height = "256";
String styles = "";
String layers = "wtx:road_hazards";
final String URL_STRING = baseURL +
"&LAYERS=" + layers +
"&VERSION=" + version +
"&SERVICE=" + service +
"&REQUEST=" + request +
"&TRANSPARENT=TRUE&STYLES=" + styles +
"&FORMAT=" + format +
"&SRS=" + srs +
"&BBOX=%f,%f,%f,%f" +
"&WIDTH=" + width +
"&HEIGHT=" + height;
GeoServerTileProvider tileProvider =
new GeoServerTileProvider(256,256) {
@Override
public synchronized URL getTileUrl(int x, int y, int zoom) {
try {
double[] bbox = getBoundingBox(x, y, zoom);
String s = String.format(Locale.US, URL_STRING, bbox[MINX],
bbox[MINY], bbox[MAXX], bbox[MAXY]);
Log.d("GeoServerTileURL", s);
URL url = null;
try {
url = new URL(s);
}
catch (MalformedURLException e) {
throw new AssertionError(e);
}
return url;
}
catch (RuntimeException e) {
Log.d("GeoServerTileException",
"getTile x=" + x + ", y=" + y +
", zoomLevel=" + zoom +
" raised an exception", e);
throw e;
}
}
};
return tileProvider;
}
}
GeoServerTileProvider
public abstract class GeoServerTileProvider extends UrlTileProvider{
// Web Mercator n/w corner of the map.
private static final double[] TILE_ORIGIN =
{-20037508.34789244, 20037508.34789244};
//array indexes for that data
private static final int ORIG_X = 0;
private static final int ORIG_Y = 1; // "
// Size of square world map in meters, using WebMerc projection.
private static final double MAP_SIZE = 20037508.34789244 * 2;
// array indexes for array to hold bounding boxes.
protected static final int MINX = 0;
protected static final int MINY = 1;
protected static final int MAXX = 2;
protected static final int MAXY = 3;
public GeoServerTileProvider(int width, int height) {
super(width, height);
}
// Return a web Mercator bounding box given tile x/y indexes and a zoom
// level.
protected double[] getBoundingBox(int x, int y, int zoom) {
double tileSize = MAP_SIZE / Math.pow(2, zoom);
double minx = TILE_ORIGIN[ORIG_X] + x * tileSize;
double maxx = TILE_ORIGIN[ORIG_X] + (x+1) * tileSize;
double miny = TILE_ORIGIN[ORIG_Y] - (y+1) * tileSize;
double maxy = TILE_ORIGIN[ORIG_Y] - y * tileSize;
double[] bbox = new double[4];
bbox[MINX] = minx;
bbox[MINY] = miny;
bbox[MAXX] = maxx;
bbox[MAXY] = maxy;
return bbox;
}
}