Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Launching Maps App Geocode type

$
0
0

I found the article below that shows how to launch the native maps app for different phones. It mentions the type Geocode, but I don't know where that comes from and it's throwing an error for me. Anyone have any ideas?

http://www.sellsbrothers.com/posts/Details/13739

Code from the article:

public class Place {
    public string Name { get; set; }
    public string Vicinity { get; set; }
    public Geocode Location { get; set; }
    public Uri Icon { get; set; }
}

public void LaunchMapApp(Place place) {
    // Windows Phone doesn't like ampersands in the names and the normal URI escaping doesn't help
    var name = place.Name.Replace("&", "and"); // var name = Uri.EscapeUriString(place.Name);
    var loc = string.Format("{0},{1}", place.Location.Latitude, place.Location.Longitude);
    var addr = Uri.EscapeUriString(place.Vicinity);

    var request = Device.OnPlatform(
        // iOS doesn't like %s or spaces in their URLs, so manually replace spaces with +s
        string.Format("http://maps.apple.com/maps?q={0}&sll={1}", name.Replace(' ', '+'), loc),

        // pass the address to Android if we have it
        string.Format("geo:0,0?q={0}({1})", string.IsNullOrWhiteSpace(addr) ? loc : addr, name),

        // WinPhone
        string.Format("bingmaps:?cp={0}&q={1}", loc, name)
    );

    Device.OpenUri(new Uri(request));
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles