B4A Library WebMapView - Easy way to get Latitude and Longitude from map

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
  • WebMapView
    Events:
    • Cancelled
    • Closed (Latitude As String, Longitude As String)
    • DragEnd (NewLatitude As String, NewLongitude As String)
    Methods:
    • 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
    Permissions:
    • android.permission.INTERNET
    Properties:
    • 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)

xLTk0um.jpg
 

Attachments

  • WebMapView_Libray.zip
    5.4 KB · Views: 419
  • WebMapView_Example.zip
    334 KB · Views: 488
  • WebMapView0.02.zip
    5.8 KB · Views: 298
  • WebMapView_03.zip
    6.1 KB · Views: 284
  • WebMapView0.04.zip
    6.4 KB · Views: 272
  • WebMapView0.05.zip
    6.4 KB · Views: 353
Last edited:

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi, i have found may be an accuracy error , try to compare the coordinates when you move marker versus googlemap with that cordinates. You can notice is not the same point in the map. How to fix this error please ?. Thank you in advance

Please check Version 0.05
 

dfrutos

Member
Licensed User
Longtime User
Hello, this library works with B4A V2.52??
I have an error in line Dim mpv As WebMapView... a fatal error, app stops immediately
 

dfrutos

Member
Licensed User
Longtime User
I have B4A 2.52 version... when i compile apk, when i execute app not work, the instance Dim mpx As WebMapView is wrong... is necesary download anything from sdk android?
 

dfrutos

Member
Licensed User
Longtime User
Dear somed3vloper, thanks for your help!

The log error is:

LogCat connected to: B4A-Bridge: HUAWEI HUAWEI G6-U251
--------- beginning of /dev/log/main
~i:** Activity (main) Resume **
Installing file.
~i:** Activity (main) Pause, UserClosed = false **
~i:** Activity (main) Resume **
~i:** Service (service1) Destroy **
~i:** Service (service1) Create **
~i:** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
Installing file.
~i:** Activity (main) Pause, UserClosed = false **
~i:** Activity (main) Resume **
Streams_terminated
Connected to B4A-Bridge (Wifi)

PackageAdded: package:anywheresoftware.b4a.designer
Installing file.
PackageAdded: package:mapaejemplo.b4a
main_globals (java line: 346)
java.lang.NoClassDefFoundError: b4a.example.webmapview
at mapaejemplo.b4a.main._globals(main.java:346)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at mapaejemplo.b4a.main.initializeGlobals(main.java:226)
at mapaejemplo.b4a.main.afterFirstLayout(main.java:86)
at mapaejemplo.b4a.main.access$100(main.java:16)
at mapaejemplo.b4a.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5494)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
 

dfrutos

Member
Licensed User
Longtime User
#Region Project Attributes
#ApplicationLabel: WebMapView Example
'SupportedOrientations possible values: unspecified, landscape or portrait.

#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","mapview","Drag the marker to set your location",15,"google.maps.MapTypeId.ROADMAP")
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
 

dfrutos

Member
Licensed User
Longtime User
Yes, if i comment this line Activity.LoadLayout("Layout1") the error is the same...
 

dfrutos

Member
Licensed User
Longtime User
Thank you Erel and somed3v3loper... i will update version... and thank you for de code... i will try now...
 
Top