Android Question Open Google maps webview with search place parameter

andrewhannay

Member
Licensed User
Longtime User
Hi,
Is it possible to open a webview of google maps with a search parameter?
For example, the user will type a place name in a text box within the app, hit a button and it will open a webview of google maps with all the hits relating to that search.
Andrew
 

andrewhannay

Member
Licensed User
Longtime User
Ah ha, thankyou, I thought there would a really simple way that made me look stupid un-yet a quick google search didn't give that answer (my background is low level embedded programming in Assembler and C).
So, assuming I can just do something like this in B4A :-
WebView1.LoadUrl(http://maps.google.com/maps?q=london)
How would I do it with LoadHtml ? (There is a reason why I have to do it this way)
Cheers,
Andrew
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
You can build your own local html file using something like this (not tested)

B4X:
dim urlstring, sourcetext as string

'Get the text entered in the text field
sourcetext=textfiedl.text '<= change for your text field

' Use the refresh function to redirect, can probably do this a different way. The 1 is for 1 second

urlstring="<html><META HTTP-EQUIV='refresh' CONTENT='1; URL=http://maps.google.com/maps?q="& sourcetext&"'><body></body></html>

WebView1.LoadHtml(ImageString1)

You might need to play with this a little.

This as a htm file works

<html><META HTTP-EQUIV="refresh" CONTENT="1; URL=http://maps.google.com/maps?q=london"><body></body></html>
 
Upvote 0

andrewhannay

Member
Licensed User
Longtime User
Any Idea how I would integrate it into this code?
I guess I wouldn't nee the lat and long positions that are passed to it, just the search parameter.
Thankyou
Andrew


Dim HtmlCode As String
HtmlCode = "<!DOCTYPE html><html><head><meta name='viewport' content='initial-scale=1.0, user-scalable=no' /><style type='text/css'> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px }#map_canvas { height: 100% }</style><script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'></script><script type='text/javascript'> function initialize() {var centerlatlng = new google.maps.LatLng(" & CenterLat & "," & CenterLong & "); var myOptions = { zoom: 15, center: centerlatlng, disableDefaultUI: true, zoomControl: false, scaleControl: false, mapTypeControl: false, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); }</script></head><body onload='initialize()'> <div id='map_canvas' style='width:100%; height:100%'></div></body></html>"
MapViewer.LoadHtml(HtmlCode)
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
You are correct. Replacing the CenterLat and CenterLong with the values 51.50735,-0.16565 will zoom the map onto Hyde Park in London.

B4X:
<!DOCTYPE html><html><head><meta name='viewport' content='initial-scale=1.0, user-scalable=no' /><style type='text/css'> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px }#map_canvas { height: 100% }</style><script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'></script><script type='text/javascript'> function initialize() {var centerlatlng = new google.maps.LatLng(51.50735,-0.16565); var myOptions = { zoom: 15, center: centerlatlng, disableDefaultUI: true, zoomControl: false, scaleControl: false, mapTypeControl: false, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); }</script></head><body onload='initialize()'> <div id='map_canvas' style='width:100%; height:100%'></div></body></html>

Declare the two variables before you declare this HtmlCode and all should be well. At least copying this text to a file and showing it in Netscape works for me.
 
Upvote 0

andrewhannay

Member
Licensed User
Longtime User
Not quite what I meant :)
I wanted to integrate the search function (eg. ?q=london) into the code above.
I need the code above to make use of the WebViewExtras Library so that I get a function call back to my code when I re-centre the map.
Or alternatively, anything that allows me to search for a place, find it on the map and get the gps coords back from the map so I can use them in my code.
Thanks again.
Andrew
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
I see no reason why it should not work. I would make a htm file and test it in a browser, it would be quicker. I did the same with your code. Pls post your solution for others.
 
Upvote 0

andrewhannay

Member
Licensed User
Longtime User
I haven't got a solution. Everything I've tried hasn't worked hence why I am here :)
I don't want to open a webview with GPS coords, that's easy, I want to do something a bit more difficult, I want open a webview with a search string and read the GPS coords back into my code or, open a standard google maps WebView with a search box and read the GPS coords back into my code. But I think this is not possible yet. Maybe it's something that nobody requires hence why there is no solution.
Thanks for your help. If anybody else comes up with a solution then it might be useful, in the meantime I'm going another route using list view and a load of place names with their GPS coords.
 
Upvote 0
Top