Skip to content

Instantly share code, notes, and snippets.

@Parmendrak
Created October 20, 2014 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Parmendrak/2e40f1af7941fc36c88f to your computer and use it in GitHub Desktop.
Save Parmendrak/2e40f1af7941fc36c88f to your computer and use it in GitHub Desktop.
using System;
using Xamarin.Forms;
namespace WorkingWithMaps
{
public class MapAppPage : ContentPage
{
// WARNING: when adding latitude/longitude values be careful of localization.
// European (and other countries) use a comma as the separator, which will break the request
public MapAppPage ()
{
var l = new Label {
Text = "These buttons leave the current app and open the built-in Maps app for the platform"
};
var openLocation = new Button {
Text = "Open location using built-in Maps app"
};
openLocation.Clicked += (sender, e) => {
if (Device.OS == TargetPlatform.iOS) {
//https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
//Device.OpenUri(new Uri("http://maps.apple.com/?q=394+Pacific+Ave+San+Francisco+CA"));
// Device.OpenUri(new Uri("http://maps.google.com/?daddr=" + openLocation));
Device.OpenUri(new Uri("http://maps.google.com/?daddr=H%c3%b6henweg+9+8966+Oberwil-Lieli+Schweiz="+openLocation));
}
else if (Device.OS == TargetPlatform.Android) {
// opens the Maps app directly
Device.OpenUri(new Uri("geo:0,0?q=394+Pacific+Ave+San+Francisco+CA"));
} else if (Device.OS == TargetPlatform.WinPhone) {
DisplayAlert("To Do", "Not yet implemented", "OK");
}
};
var openDirections = new Button {
Text = "Get directions using built-in Maps app"
};
openDirections.Clicked += (sender, e) => {
if (Device.OS == TargetPlatform.iOS) {
//https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
//Device.OpenUri(new Uri("http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino"));
Device.OpenUri(new Uri("http://maps.google.com/?daddr=H%c3%b6henweg+9+8966+Oberwil-Lieli+Schweiz"));
} else if (Device.OS == TargetPlatform.Android) {
// opens the 'task chooser' so the user can pick Maps, Chrome or other mapping app
//Device.OpenUri(new Uri("http://maps.google.com/?daddr=San+Francisco,+CA&saddr=Mountain+View"));
Device.OpenUri(new Uri("http://maps.google.com/?daddr=H%c3%b6henweg+9+8966+Oberwil-Lieli+Schweiz"));
} else if (Device.OS == TargetPlatform.WinPhone) {
DisplayAlert("To Do", "Not yet implemented", "OK");
}
};
Content = new StackLayout{
Padding = new Thickness (5, 20, 5, 0),
HorizontalOptions = LayoutOptions.Fill,
Children = {
l,
openLocation,
openDirections
}
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment