Android Question How to show postal code boundary via intent

toby

Well-Known Member
Licensed User
Longtime User
https://www.google.com/maps/place/10004,US shows Zip Code 10004 area highlighted with boundary border, as shown in the attached image.
showpostalcodeboundary.jpg


However the following code, using the identical url, only zooms to somewhere within the area, no border, nor highlighting.
B4X:
    Dim i As Intent
    Dim url As String= $"https://www.google.com/maps/place/10004,US"$
    Log(url)
    i.Initialize(i.ACTION_VIEW,url)
    i.SetComponent("com.google.android.apps.maps/com.google.android.maps.MapsActivity")
    StartActivity(i)

How the intent should be changed to have the same effects?

TIA
 
Solution
I've ended up using Webview instead
B4X:
Sub showPostcodeBoundary(postCode As String, countryCode As String)
    Dim url1 As String= $"https://www.google.com/maps/place/${postCode},${countryCode}"$
    Log(url1)
    WebView1.LoadUrl(url1)
End Sub

Notes:
1. Some postal codes don't show a boundary.
2. If browser doesn't show the boundary, then don't expect Webview to do so
3. If no boundary shown initially when map appears, try zooming in.

example uses:
 showPostcodeBoundary("10004", "US") 'battery park, new york, new york, US
    'showPostcodeBoundary("M5J2N1", "CA") 'TORONTO union station

toby

Well-Known Member
Licensed User
Longtime User
I tried browsing to the url and it didn't work either.
B4X:
Dim p As PhoneIntents 'lib: phone
StartActivity(p.OpenBrowser(url))
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
a number of people have made the same inquiry. postal boundaries are, from
what i understand, available in google mapsfor u.s. and u.k., but there is no api to access them.

at low zoom levels, the map tile for 10004 actually contains the postal boundary in
the tile. that is, it's not an added layer. if you ask for the right tile, you'll see it. it's not
difficult to find. google has apparently determined it's faster to create the boundary as
part of the tile rather than displaying the tile and drawing a layer on top of it.

at higher zoom levels, it appears to be a sort of drawn polygon with encoding that is
not like google's polygon api.

depending on your needs (apart from simply running google maps in a browser),
shape maps are out there (presumably, you already know this). it would be possible
to convert a shape map to a geojson object and add it as a layer to a map app.

if what you wanted was a little static map showing all postal code boundaries in
manhattan, that is also doable: there are, what, 27 of them as i recall. you could
collect all 27 and show them, as needed, in your app. google wouldn't be thrilled,
but maybe they never see your app. a couple hours of your time.

in any case, it seems that the postal boundaries are only available in a desktop browser.
if you could convince google that your android chrome was a desktop chrome, it might
work. i'm guessing you would have to tweak the user-agent header, but i'm sure
google has already taken such things into account.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I've ended up using Webview instead
B4X:
Sub showPostcodeBoundary(postCode As String, countryCode As String)
    Dim url1 As String= $"https://www.google.com/maps/place/${postCode},${countryCode}"$
    Log(url1)
    WebView1.LoadUrl(url1)
End Sub

Notes:
1. Some postal codes don't show a boundary.
2. If browser doesn't show the boundary, then don't expect Webview to do so
3. If no boundary shown initially when map appears, try zooming in.

example uses:
 showPostcodeBoundary("10004", "US") 'battery park, new york, new york, US
    'showPostcodeBoundary("M5J2N1", "CA") 'TORONTO union station
 
Last edited:
Upvote 0
Solution
Top