Google Map Marker

Lon

Member
Licensed User
Longtime User
Does anyone have an example of how to retrieve the new location (Lat,Long) of a movable marker after it is dropped on the map? Thx.
 

lagore

Active Member
Licensed User
Longtime User
Hi if you follow Klaus's mapview http://www.b4x.com/forum/basic4android-updates-questions/12573-webview-google-map.html#post71003 this uses a webview and 'WebViewExtras' then we need to add a listener for for the marker 'Dragend Event' add the following after the marker declaration (note marker0 is the name of my coded marker)
B4X:
HtmlCode = HtmlCode & ";google.maps.event.addListener(marker0, 'dragend', function() {"
      HtmlCode = HtmlCode & "var MyMarker = marker0.getPosition();"
      HtmlCode = HtmlCode & "B4A.CallSub('MapViewer_MarkerChanged', true, MyMarker.lat(), MyMarker.lng() );"
      HtmlCode = HtmlCode & " })"
then we create a sub that is directed to from the javascript in the webview called "MapViewer_MarkerChanged" this has the coordinates of the dropped marker (once again 'MapViewer_MarkerChanged' was the code I used you can use anything once it all matches)
B4X:
Sub MapViewer_MarkerChanged(Lat As String, Lng As String)
   Log(Lat & "," & Lng)
End Sub
You can also add 'Dragstart' and 'drag' listeners if you want to get the start marker position and the moving marker position.
 
Upvote 0

Lon

Member
Licensed User
Longtime User
That works great! Thanks so much for your help.
Only problem now is that I find it really hard to grab the little markers with my big fat finger. Is there any way to increase the "contact" size of the marker to make them easier to grab?
 
Upvote 0

Lon

Member
Licensed User
Longtime User
I can't seem to get Klaus's mapview to work on the AVD with API Level 10 running. The program just exits. All the other API levels seem to run it without any problems. Does anyone know if that is a problem with actual devices as well or is it just a AVD problem?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…