这不完全是您问题的答案,而是另一种选择;
我一直在使用 OpenStreetMaps 与传单和/或使用xamarin over android 的 mapbox。虽然我不确定你是否可以过滤掉加油站。
这是我用来渲染移动地图的代码;
public class MainActivity : Activity//, ILocationListener
{
private WebView _webView;
private MonkeyWebViewClient _webViewClient;
private MonkeyWebChromeClient _webChromeClient;
...
protected override void OnCreate (Bundle bundle)
{
Log.Verbose (LogAppTag, "Init webview..");
_webView = FindViewById<WebView> (Resource.Id.webView1);
_webView.Settings.JavaScriptEnabled = true;
_webViewClient = new MonkeyWebViewClient (this);
_webChromeClient = new MonkeyWebChromeClient ();
_webViewClient.OnLoadComplete += WebLoadComplete;
_webView.SetWebViewClient(_webViewClient);
_webView.SetWebChromeClient(_webChromeClient);
_webView.LoadUrl("file:///android_asset/Content/Map/Map.html");
...
void WebLoadComplete (object sender, EventArgs e)
{
Log.Verbose(Logging.AppTag, "WebLoadComplete()");
_webView.LoadUrl("javascript:SetLocation(" + _location.Latitude + "," + _location.Longitude + ");");
}
...
class MonkeyWebChromeClient : WebChromeClient {
public override bool OnJsAlert(WebView view, string url, string message, JsResult result)
{
// the built-in alert is pretty ugly, you could do something different here if you wanted to
return base.OnJsAlert(view, url, message, result);
}
}
class MonkeyWebViewClient : WebViewClient
{
public bool LoadingFinished { get; private set; }
public delegate void LoadCompleteHandler(object sender, EventArgs e);
public event LoadCompleteHandler OnLoadComplete;
Activity context;
public MonkeyWebViewClient(Activity context)
{
this.context = context;
}
public override bool ShouldOverrideUrlLoading(WebView view, string url)
{
view.LoadUrl (url);
return true;
}
public override void OnPageStarted (WebView view, string url, Android.Graphics.Bitmap favicon)
{
this.LoadingFinished = false;
base.OnPageStarted (view, url, favicon);
}
public override void OnPageFinished (WebView view, string url)
{
this.LoadingFinished = true;
var handler = OnLoadComplete;
if (handler != null) handler(this, EventArgs.Empty);
base.OnPageFinished (view, url);
}
}
这是我们在 webview 中加载的 html 代码;
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- mapbox -->
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.css' rel='stylesheet' />
<!-- mapbox -->
</head>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
<div id="map"></div>
<script src="JS/Map.js"></script>
</html>
以及可以与C#代码通信的JS代码;您可能想在 mapbox 上创建一个新地图并更改 raistlinthewiz.map-oukwofv3 部分。
// map code.
function SetLocation(lat, lng)
{
var latlng = new L.LatLng(parseFloat(lat), parseFloat(lng));
// mapbox
var map = L.mapbox.map('map', 'raistlinthewiz.map-oukwofv3').setView(latlng, 18);
L.mapbox.markerLayer({ // this feature is in the GeoJSON format: see geojson.org for the full specification
type: 'Feature',
geometry: {
type: 'Point', // coordinates here are in longitude, latitude order because x, y is the standard for GeoJSON and many formats
coordinates: [parseFloat(lng), parseFloat(lat)]
},
properties: { // one can customize markers by adding simplestyle properties http://mapbox.com/developers/simplestyle/
title: 'A Single Marker',
description: 'Just one of me',
'marker-size': 'large'
}
}).addTo(map);
}
如果您还需要,我可以提供一个使用 vanilla-leaflet 的示例。