B4J Question jGoogleMaps - Displaying An Area

RichardN

Well-Known Member
Licensed User
Longtime User
In the web version of Google Maps I can enter a search clue like "Borough Of Islington" and it is correctly interpreted as an area rather than a single location. The result is a faithful camera view over the London Borough Of Islington with the border clearly marked out with a red dotted line.

I am unable to reproduce this dotted area with jGoogleMaps. Using the code below the camera is correctly moved to the centre of the Borough but there is no red dotted line around the perimeter. My GoogleMaps API key is enabled for Maps Javascript API and Places API. Perhaps I am not employing the correct JSON information? Anybody tried this before?

jGoogleMaps Retrieve Places:
Sub btnSearch_Click

    If txtClue.Text = "" Then Return
    clue = txtClue.Text.Replace(" ","%20")
    
    Dim j As HttpJob
    j.Initialize("", Me)
    
    Dim URL As String = "https://maps.googleapis.com/maps/api/place/textsearch/json"
    Dim Query As String = "?query=" & clue & "&key=" & APIkey

    j.Download(URL & Query)
        
    Wait For (j) JobDone (j As HttpJob)
    
    If j.Success Then
        
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim root As Map = parser.NextObject
        Dim results As List = root.Get("results")
        Dim colres As Map = results.Get(0)
        Dim geometry As Map = colres.Get("geometry")
        Dim location As Map = geometry.Get("location")
        
        Dim Lat,Lon As Double
        Lat = location.Get("lat")
        Lon = location.Get("lng")
        
        Dim cp As CameraPosition
        cp.Initialize(Lat, Lon, 17)
        gMap.MoveCamera(cp)
        
    End If

    j.Release
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Using the code below the camera is correctly moved to the centre of the Borough but there is no red dotted line around the perimeter.
you need to build it by yourself.
you are totally ignoring
B4X:
 Dim results As List = root.Get("results")
        Dim colres As Map = results.Get(0)
        Dim geometry As Map = colres.Get("geometry")
        Dim location As Map = geometry.Get("location")
any other Result than the first item.
Go over the list and build from that info...
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Thanks @DonManfred,

I already checked the JSON and there appear to be no clues as to what information the perimeter might be constructed from. I can see a centrepoint location and some NE/SW view bounds. There is also some photo information but nothing else useful. Maybe a different query is needed? Maybe the Lib simply does not support it?
 

Attachments

  • JSON.txt
    1.7 KB · Views: 163
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
and with some math these NE/SW-Bounds can be used to paint 4 lines resp the box you are asking about
@DonManfred

Clearly this statement is true but sadly it has nothing to do with the question I asked which was about depicting administrative borders.

Reading around the subject it appears the Google Cloud API now provides the facility to create bespoke maps depicting details like administrative areas so a Javascript solution is possible. Unfortunately it seems this functionality cannot be exploited with the current jGoogleMaps library.
 
Upvote 0
Top