Android Tutorial Googlemaps V3 In A Webview

Cor

Active Member
Licensed User
Longtime User
Hello Klaus,

dragging on the device is working

but can we have an event when dragging is done?

same as clicking

maybe it is not supported yet by webview

Maybe Erel can answer this
 

wes58

Active Member
Licensed User
Longtime User
Is there any way to update position of the marker if position of the marker changes without redrawing (downloading) the whole map again?
 

klaus

Expert
Licensed User
Longtime User
...but can we have an event when dragging is done?
The event does exist in the GoogleMaps API.
dragstart, drag and dragend do exist and return the marker position.

But as Erel said those are not supported in the WebView view.

@wes58
This would be possible with the dragend event. But not supported (yet ? )

By the way, the title parameter of a marker has no effect on the display either.

Best regards.
 

klaus

Expert
Licensed User
Longtime User
Is there any way to update position of the marker if position of the marker changes without redrawing (downloading) the whole map again?
This is possible now, thanks to warwounds WebViewExtra library.
Have a look at the GPS Example it's in the MapDisp routine.

Best regards.
 

gehrlekrona

Member
Licensed User
Longtime User
Webview and Clickable markers/labels?

Hi, is it possible using the webview and get clickable markers? Witth clickable makers I mean like in a "real" browser you can have URL's that you can click on and get to the web page, but it doesn't seem to work with the webview.
I can open up the webview (web page with google maps and markers) and I can click on the URL in the info window, but it doesn't work in Webview.

Anyone?
 
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
Click and moving to position without refreshing the map

Hi Klaus,

I still cannot get the click event done, all code is there to execute it but the event isn't generated.

Also something else, where exactly in the MapDisp code is something that shows a new position without loading the whole HTML again?

Cheers,
 

CidTek

Active Member
Licensed User
Longtime User

Does anyone know how to get zoom to fit working with the Webview code sample Klaus posted?
 

CidTek

Active Member
Licensed User
Longtime User
Sorry, but I don't understand what exactly you want to do.
You can find a more advanced routine in the GPS Example program.

Best regards.

Instead of assigning a fixed zoom I would like the map to to zoom in tight as possible but still include all the markers. Current location wouldn't necessarily be centered but thats not a problem.
 

klaus

Expert
Licensed User
Longtime User
In the GPSExample program I did it that way:
B4X:
Sub CalcMapZoom
    ' Calculates the bounds of a GPS path and the zoom level
    Dim i As Int
    Dim Scale As Double
    Dim Scale0 As Double
    
    GPSPathLngMax = -180
    GPSPathLngMin = 180
    GPSPathLatMax = -90
    GPSPathLatMin = 90
    
    ' calculate the min and max lat, lng values of the GPS path
    For i = 0 To GPSPath.Size -1
        Dim loc As GPSLocation
        loc = GPSPath.Get(i)
        GPSPathLngMax = Max(GPSPathLngMax, loc.Longitude)
        GPSPathLngMin = Min(GPSPathLngMin, loc.Longitude)
        GPSPathLatMax = Max(GPSPathLatMax, loc.Latitude)
        GPSPathLatMin = Min(GPSPathLatMin, loc.Latitude)
    Next
    
    GPSPathLngMean = (GPSPathLngMax + GPSPathLngMin) / 2
    GPSPathLatMean = (GPSPathLatMax + GPSPathLatMin) / 2
    
    MapZoomLevel = 20
    Scale0 = MapViewer.Width / TileSize * 360 
    If (GPSPathLngMax - GPSPathLngMin) / MapViewer.Width > (GPSPathLatMax - GPSPathLatMin) / MapViewer.Height / CosD(GPSPathLatMean) Then
        Scale = Scale0 / Power(2, MapZoomLevel)
        Do While Scale <= GPSPathLngMax - GPSPathLngMin
            MapZoomLevel = MapZoomLevel - 1
            Scale = Scale0 / Power(2, MapZoomLevel)
        Loop
    Else
        Scale0 = Scale0 / CosD(GPSPathLatMean)
        Scale = Scale0 / Power(2, MapZoomLevel)
        Do While Scale <= GPSPathLatMax - GPSPathLatMin
            MapZoomLevel = MapZoomLevel - 1
            Scale = Scale0 / Power(2, MapZoomLevel)
        Loop
    End If
End Sub
Best regards.
 

CidTek

Active Member
Licensed User
Longtime User

CidTek

Active Member
Licensed User
Longtime User
I have modified your sample project and added the CalcMapZoom code you posted today. It seems that it is zooming in too much.

I have attached the test project and if you comment out line 77 you will get the original hardcoded zoom=15 otherwise it uses your CalcMapZoom code.

Any ideas?
 

Attachments

  • GoogMapsPlusAutoZoom.zip
    7.2 KB · Views: 465

CidTek

Active Member
Licensed User
Longtime User
Hi Klaus, have you had a chance to look at the sample code I uploaded? The CalcMapZoom is zooming in too tight.
 

CidTek

Active Member
Licensed User
Longtime User
Well I finally got the javascript working for zooming to fit the boundary of all the marker pins.

All this time my problem was not being aware of case sensitive issues with js code and a single 'Map' instead of 'map' was thwarting me.

I have attached the sample code in a project that does not do much except highlight the technique of placing markers and then fitting the zoom level based on the boundary.

You can comment out or add more locations to see the changes in zoom level.

For some reason tapping a pin is not showing the title but I only noticed this now as I have to post and run.
 

Attachments

  • GoogleMapsV3AutoZoom.zip
    6.9 KB · Views: 582
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…