OpenStreetMap und Leaflet auf Android

  • Antworten:0
Bernd Roth
  • Forum-Beiträge: 98

23.09.2013, 22:50:29 via Website

Hallo Forum,
ich hänge bei folgendem Problem fest.

Wie ich gelesen habe, kann man mittels Leaflet Polygone einfacher und schneller darstellen als ich es vormals getan habe.

Jetzt ist nur mein grosses Problem, dass ich aus dem Tutorial von Leaflet nicht wirklich schlau werde.

Ich habe zwar in meinem assets folder folgende Datei:basic.html mit folgendem Inhalt abgespeichert:

1<!DOCTYPE html>
2<head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
4 <link rel="stylesheet" href="./leaflet-0.5.css" />
5 <script>L_PREFER_CANVAS = true;</script>
6 <script type="text/javascript" charset="utf-8" src="./leaflet-src-0.5.js"></script>
7 <style>
8 body {
9 padding: 0;
10 margin: 0;
11 }
12 html, body, #map {
13 height: 100%;
14 }
15 </style>
16</head>
17<body>
18 <div id="map"></div>
19
20 <script>
21
22 var map = L.map('map');
23
24 L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
25 attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
26 maxZoom: 18
27 }).addTo(map);
28 map.locate({setView: true, maxZoom: 16});
29 function onLocationFound(e) {
30 var radius = e.accuracy / 2;
31
32 L.marker(e.latlng).addTo(map)
33 .bindPopup("You are within " + radius + " meters from this point").openPopup();
34
35 L.circle(e.latlng, radius).addTo(map);
36 }
37
38 map.on('locationfound', onLocationFound);
39 function onLocationError(e) {
40 alert(e.message);
41 }
42
43 map.on('locationerror', onLocationError);
44
45
46
47
48 </script>
49</body>
50</html>

Jedoch weiss ich nicht, wie ich das Ganze in meiner Activity von Android aufrufe?
Ich habe es mir so etwa gedacht:

1public class AndroidOpenStreetMapViewActivity extends Activity {
2
3 private MapView myOpenMapView;
4 private MapController myMapController;
5
6 LocationManager locationManager;
7
8 ArrayList<OverlayItem> overlayItemArray;
9
10 /** Called when the activity is first created. */
11 private WebView mWebView;
12 @Override
13 protected void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);
15 setContentView(R.layout.activity_main);
16 mWebView= (WebView)findViewById(R.id.map);
17 mWebView.setWebChromeClient(new WebChromeClient());
18 mWebView.loadUrl("file:///android_asset/basic.html");
19 }
20}

Leider bricht er aber mit einer Fehlermeldung ab:

Binay XML file line #13 ...

Leider finde ich im Internet auch kein komplettes Beispiel dazu, wie oder was ich genau alles zu tun habe.
An einem Beispiel könnte ich mich wenigstens weiterhangeln, aber leider scheitere ich bereits beim Laden, da ich hierzu nichts Passendes finde.

Vll. hat jemand eine Idee oder schon einmal Leaflet mit Openstreetmap verwendet.

Bin für jede Hilfe sehr dankbar!

lG

Antworten