Hi all ,
Here is a very simple library to add an html based map view to select a location by dragging a marker and then getting point Latitude and Longitude .
I used some code from this example and of course WebViewExtras library . Thanks Martin
WebMapView
Author: "SMM"
Version: 0.03
An example :
Version 0.05 : Accuracy issue found and fixed by ArmazolZerpa thank you
Version 0.04 : You can get rid of buttons below map by passing empty strings like :
Here is a very simple library to add an html based map view to select a location by dragging a marker and then getting point Latitude and Longitude .
I used some code from this example and of course WebViewExtras library . Thanks Martin
WebMapView
Author: "SMM"
Version: 0.03
- WebMapView
Events:- Cancelled
- Closed (Latitude As String, Longitude As String)
- DragEnd (NewLatitude As String, NewLongitude As String)
- IsInitialized As Boolean
Tests whether the object has been initialized. - Initialize (act As PanelWrapper, Module As Object, Ok As String, cancel As String, startlat As String, startlon As String, event As String, prompt As String, mapzoom As Int, MapTypeId As String) As String
- Initializes the Map.
act = Your activity or panel
Module = calling module to receive Map Events.
Ok = Ok button.Text.
cancel = Cancel button.Text
startlat = The starting Latitude .
startlon = The starting Longitude .
event = Event Prefix for map events.
prompt = Text to show above the map . Pass empty string for larger map.
mapzoom = zoom level : larger = closer .
MapTypeId = Google Map Types
You can use the following:
WepMapView.ROADMAP displays the default road map view. This is the default map type.
WepMapView.SATELLITE displays Google Earth satellite images
WepMapView.HYBRID displays a mixture of normal AND satellite views
WepMapView.TERRAIN displays a physical Map based on terrain information. - Remove_me As String
Remove map view from its parent - Reset_location (newlat As String, newlon As String) As String
Reset marker and map center to New Latitude and Longitude provided . - Setmaptype (MapType As String) As String
Set Map view type like "google.maps.MapTypeId.ROADMAP" - Show_me As String
Add the map to the activity
Typically used after Initializing the map
- android.permission.INTERNET
- Hybrid As String [read only]
displays a mixture of normal and satellite views - Roadmap As String [read only]
displays the default road map view - Satellite As String [read only]
displays Google Earth satellite images - Terrain As String [read only]
displays a physical map based on terrain information
An example :
B4X:
#Region Project Attributes
#ApplicationLabel: WebMapView Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim mapv As WebMapView
Dim btn As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
btn.Initialize("btn")
btn.Text="Show WebMapView"
Activity.AddView(btn,0,0,100%x,10%y)
mapv.Initialize(Activity,Me,"OK","Cancel","48.8567","2.3508","webmap","Specify your location :",13,mapv.ROADMAP)
wmv.Show_Me
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btn_Click
mapv.Show_Me
End Sub
Sub mapview_DragEnd(lat As String,lon As String)
Log("Dragged to "&lat&","&lon)
End Sub
Sub mapview_Closed(lat As String,lon As String)
Log("Closed with "&lat&","&lon)
End Sub
Sub mapview_Cancelled
Log("Cancelled")
End Sub
Version 0.05 : Accuracy issue found and fixed by ArmazolZerpa thank you
Version 0.04 : You can get rid of buttons below map by passing empty strings like :
B4X:
mapv.Initialize(Activity,Me,"","","48.8567","2.3508","webmap","Specify your location :",13,mapv.ROADMAP)
Attachments
Last edited: