开发者

Launch maps from within Android WebView

开发者 https://www.devze.com 2023-03-20 02:50 出处:网络
I have an Android app that displays content in a WebView which includes a link which should open up a map. I have the latitude, longitude and the s开发者_高级运维treet address of the location I want t

I have an Android app that displays content in a WebView which includes a link which should open up a map. I have the latitude, longitude and the s开发者_高级运维treet address of the location I want to link to, but I'm not sure of the correct format for the link.


Haven't received any answers or comments from the community on this one for about a week... In the end I've just gone with:

http://maps.google.com/?ll={lat},{lon}q={address}

The phone was smart enough to detect this was a link to a map and open up the Maps activity to display it.

I also tried using the geo:{lat},{lon}?{address} link format, which did open up the map at the correct location, but the zoom was way too close and there was no mention of the actual address.

Ideally, I'm still looking for an answer that allows me to catch the link being opened from the WebView and open up a new MapView where I can drop my own pins and balloons and keep the user within my own application.


I will list solutions to incorporating maps into your application in order of degree of complication since I am unaware which method you require exactly.

To load the map in Google's Maps (or the device's default maps application):

This is super easy using the geo: URI! Go here for documentation on its usage.

To load the map inside its own Fragment:

Checkout the documentation found here for coding maps inside their own fragments. It has further example code on: Changing the Map Type, Indoor Maps, Setting Custom Markers and Information windows, Flat Markers, and Polylines.

To load the map inside your webpage in your WebView:

Check out the documentation found here for coding the map into the HTML.

Note: I highly recommend you use the Fragment method since you can do some really beautiful stuff.

0

精彩评论

暂无评论...
验证码 换一张
取 消