- Forum-Beiträge: 98
27.06.2014, 23:24:30 via Website
27.06.2014 23:24:30 via Website
Hallo Forum,
ich möchte gerne einen String, der ein JSON Object repräsentiert, von einer Activity zum Javascript - Code überreichen!
Hardcoded funktioniert alles innerhalb des JavaScriptes - Code, jetzt geschieht die Erzeugung der Lat / Lon Werte dynamisch.
Leider schaffe ich es nicht trotz Tutorials es hinzubekommen.
Vll. kann mir jemand weiterhelfen ( bitte nicht schlagen für den grauslichen Code! )
Danke schon einmal vielmals!
Webview:
<script type='text/javascript'>
function init()
{
var map = new L.Map ("map1"
var attrib="";
var layerOSM = new L.TileLayer
("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
{ attribution: attrib } );
map.addLayer(layerOSM);
var auto = L.icon({
iconUrl: 'auto.png',
//shadowUrl: 'auto.png',
iconSize: [50, 50], // size of the icon
//shadowSize: [50, 64], // size of the shadow
iconAnchor: [100, 70], // point of the icon which will correspond to marker's location
//shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [100, 70] // point from which the popup should open relative to the iconAnchor
});
//map.on("click",onMapClick)
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
map.locate({setView: true, maxZoom: 15});
function onMapClick(e)
{
// "e.latlng" is an L.LatLng object representing the mouse click position
var clickedPosition = e.latlng;
alert("You clicked at: " + clickedPosition.lat + " " + clickedPosition.lng);
}
function onLocationFound(e) {
var radius = e.accuracy / 2;
//L.marker(e.latlng).addTo(map).bindPopup("You are within " + radius + " meters from this point".openPopup();
//L.circle(e.latlng, radius).addTo(map);
L.marker(e.latlng, {icon: auto}).addTo(map);
}
function onLocationError(e) {
alert(e.message);
}
***var Kurzparkzonen=AndroidFunction.printLatLong();***
L.control.scale().addTo(map);
L.geoJson( Kurzparkzonen, {
style: function (feature) {
return { opacity: 0, fillOpacity: 0.5, fillColor: "#0f0" }; //Farbe: Green
},
onEachFeature: function(feature, layer){
layer.bindPopup("Dauer: " + feature.properties.DAUER + " | " + "Kurzparkzone: " + feature.properties.ZEITRAUM);
}
}).addTo(map);
L.geoJson( Parkstreifen, {
style: function (feature) {
return { opacity: 0, fillOpacity: 0.5, fillColor: "#0400ff" }; // Farbe: Blau
},
onEachFeature: function(feature, layer){
layer.bindPopup("Dauer: " + feature.properties.DAUER + " | " + "Parkstreifen: " + feature.properties.ZEITRAUM);
}
}).addTo(map);
L.geoJson( Parkanlage, {
style: function (feature) {
return { opacity: 0, fillOpacity: 0.5, fillColor: "#2b0aff" }; // Farbe: Blau
},
onEachFeature: function(feature, layer){
layer.bindPopup("Dauer: " + feature.properties.OEFF_ZEITEN + " | " + "Parkanlage: " + feature.properties.PARKANLAGE);
}
}).addTo(map);
L.geoJson( ParkAndRide, {
style: function (feature) {
return { opacity: 0, fillOpacity: 0.5, fillColor: "#f2ff7a" }; // Farbe: Gelb
},
onEachFeature: function(feature, layer){
layer.bindPopup("Bezirk: " + feature.properties.BEZIRK + " | " + "Park & Ride: " + feature.properties.ADRESSE);
}
}).addTo(map);
}
</script>
</head>
<body onload="init()">
WebView browser;
browser=(WebView)findViewById(R.id.webview1);
WebSettings webSettings = browser.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setGeolocationEnabled(true);
GeoClient geo = new GeoClient();
browser.setWebChromeClient(geo);
String origin = ""; //how to get origin in correct format?
geo.onGeolocationPermissionsShowPrompt(origin, this); //obviously not how this is meant to be used but expected usage not documented
browser.getSettings().setJavaScriptEnabled(true);
final MyJavaScriptInterface myJavaScriptInterface = new MyJavaScriptInterface(this, message);
browser.addJavascriptInterface(myJavaScriptInterface, "AndroidFunction"
public class MyJavaScriptInterface {
Context mContext;
String marrayFromWebsite;
MyJavaScriptInterface(Context c, String arrayFromWebsite) {
mContext = c;
marrayFromWebsite = arrayFromWebsite;
}
public void showToast(String toast){
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
public void openAndroidDialog(){
AlertDialog.Builder myDialog = new AlertDialog.Builder(WebViewActivity.this);
myDialog.setTitle("DANGER!"
myDialog.setMessage("You can do what you want!"
myDialog.setPositiveButton("ON", null);
myDialog.show();
}
public String printLatLong(){
return this.marrayFromWebsite;
}
}
lG
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.