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: 491
  • WebMapView_Example.zip
    334 KB · Views: 554
  • WebMapView0.02.zip
    5.8 KB · Views: 366
  • WebMapView_03.zip
    6.1 KB · Views: 344
  • WebMapView0.04.zip
    6.4 KB · Views: 337
  • WebMapView0.05.zip
    6.4 KB · Views: 418
Last edited:

jsk001

Member
Licensed User
Longtime User
Thank you for a great Library (and sorry for my english).
I need a information if it's possible to set a zoom value
for the map by using a value (not via +/+ Button) and
activate/deactivate the satellite view via code ???
Second Quaestion:
Is it possible to place next to the pin to display a
text information ...Pin info... (like a bubble e.g.) via code.
Thanks for the help in advance.

Best regards
 
Last edited:

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thank you for a great Library (and sorry for my english).
I need a information if it's possible to set a zoom value
for the map by using a value (not via +/+ Button) and
activate/deactivate the satellite view via code ???
Second Quaestion:
Is it possible to place next to the pin to display a
text information ...Pin info... (like a bubble e.g.) via code.
Thanks for the help in advance.

Best regards

You are welcome .
I will check what I can do and will post an update .
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thank you very much for your efforts. I would appreciate a solution
Thanks for your help in advance.
With best regards
Joachim

WebMapView0.02.zip has been uploaded with some changes .
Please check and reply if it worked for you .

Is it possible to place next to the pin to display a
text information ...Pin info... (like a bubble e.g.) via code.
Still , I will check for Pin info later .
 

jsk001

Member
Licensed User
Longtime User
WebMapView0.02.zip has been uploaded with some changes .
Please check and reply if it worked for you .


Still , I will check for Pin info later .
Thank you so much for your fast support.
I'll test is tomorrow and report you the results.

I wish you a nice weekend ...With the best regards..

...could you give me a information about the value range of mapzoom and
a info about MapTypeID (no info in bubble helb of .Initialize)

WebMapView.jpg


---> I've found the Info's i need:
mapzoom: 0 to 19
MapTypeID:
  • MapTypeId.ROADMAP
  • MapTypeId.SATELLITE
  • MapTypeId.HYBRID
  • MapTypeId.TERRAIN
...and thank you, it works great...
 
Last edited:

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thank you so much for your fast support.
I'll test is tomorrow and report you the results.

I wish you a nice weekend ...With the best regards..

...could you give me a information about the value range of mapzoom and
a info about MapTypeID (no info in bubble helb of .Initialize)

View attachment 32398

---> I've found the Info's i need:
mapzoom: 0 to 19
MapTypeID:
  • MapTypeId.ROADMAP
  • MapTypeId.SATELLITE
  • MapTypeId.HYBRID
  • MapTypeId.TERRAIN
...and thank you, it works great...

Sorry , I will update documentation .
 

jsk001

Member
Licensed User
Longtime User
Sorry , I will update documentation .

There is no Problem. You've made a great job

I've checked the new functionality and it works fine.
In sample must be changed the following...

B4X:
Dim zoom As Int:zoom=15 'value from 0..19
   mapv.Initialize(Activity,Me,"OK","Cancel","48.8567","2.3508","mapview","Drag the marker to set your location",zoom,"google.maps.MapTypeId.ROADMAP")
   'mapv.Initialize(Activity,Me,"OK","Cancel","48.8567","2.3508","mapview","Drag the marker to set your location",zoom,"google.maps.MapTypeId.HYBRID")
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
There is no Problem. You've made a great job

I've checked the new functionality and it works fine.
In sample must be changed the following...

B4X:
Dim zoom As Int:zoom=15 'value from 0..19
   mapv.Initialize(Activity,Me,"OK","Cancel","48.8567","2.3508","mapview","Drag the marker to set your location",zoom,"google.maps.MapTypeId.ROADMAP")
   'mapv.Initialize(Activity,Me,"OK","Cancel","48.8567","2.3508","mapview","Drag the marker to set your location",zoom,"google.maps.MapTypeId.HYBRID")
V0.3 Uploaded with Properties (methods) to help with map type Id .
 

jsk001

Member
Licensed User
Longtime User
Thank you for the new Revision of WebMapView. It works fine.
To select the map type you can use 3 ways:

B4X:
 'Dim SelectedMapType ="google.maps.MapTypeId.HYBRID" As String
   'MapView1.Initialize(Activity,Me,"Close","Reset Pos",Lat,Lon,"mapview",Car,Zoom,SelectedMapType)
   'MapView1.Initialize(Activity,Me,"Close","Reset Pos",Lat,Lon,"mapview",Car,Zoom,MapView1.HYBRID)
   MapView1.Initialize(Activity,Me,"Close","Reset Pos",Lat,Lon,"mapview",Car,Zoom,"google.maps.MapTypeId..HYBRID")
   MapView1.Show_Me
V0.3 Uploaded with Properties (methods) to help with map type Id .

It would be nice if you could add a feature "MarkerInfo"
(bubble info for the marker). Thank you for a great job.
 
Last edited:

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thank you for the new Revision of WebMapView. It works fine.
To select the map type you can use 3 ways:

B4X:
 'Dim SelectedMapType ="google.maps.MapTypeId.HYBRID" As String
   'MapView1.Initialize(Activity,Me,"Close","Reset Pos",Lat,Lon,"mapview",Car,Zoom,SelectedMapType)
   'MapView1.Initialize(Activity,Me,"Close","Reset Pos",Lat,Lon,"mapview",Car,Zoom,MapView1.HYBRID)
   MapView1.Initialize(Activity,Me,"Close","Reset Pos",Lat,Lon,"mapview",Car,Zoom,"google.maps.MapTypeId..HYBRID")
   MapView1.Show_Me


It would be nice if you could add a feature "MarkerInfo"
(bubble info for the marker). Thank you for a great job.

Sorry I was not successful in adding MarkerInfo.
If I get time later I will give it another try
 

jsk001

Member
Licensed User
Longtime User
Sorry I was not successful in adding MarkerInfo.
If I get time later I will give it another try

There is no problem.
I can use the parameter "Prompt" from MapView.Initialize.
Maybe you can find later still a solution

Best regards jsk001
 

ArmazolZerpa

New 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
 
Top