Xamarin.Forms.Maps provides a cross-platform abstraction for displaying maps. To use Xamarin.Forms.Maps, application developers must calls Xamarin.FormsMaps.Init() as part of platform initialization, as shown in the following example:
C# Example
//Shared
public class App
{
public static Page GetMainPage ()
{
return new ContentPage {
Content = new Map (MapSpan.FromCenterAndRadius (new Position (37, -122), Distance.FromMiles (10)))
};
}
}
//iOS
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Forms.Init ();
FormsMaps.Init ();
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = App.GetMainPage ().CreateViewController ();
window.MakeKeyAndVisible ();
return true;
}
}
//Android
namespace HelloMap.Android
{
[Activity (Label = "HelloMap.Android.Android", MainLauncher = true)]
public class MainActivity : AndroidActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Xamarin.Forms.Forms.Init (this, bundle);
FormsMaps.Init(this, bundle);
SetPage (App.GetMainPage ());
}
}
}
| Type | Reason |
|---|---|
| Distance | Struct that encapsulates a distance (natively stored as a double of meters). |
| Geocoder | Converts between string addresses and Xamarin.Forms.Maps.Positions. |
| Map | A Xamarin.Forms.View that shows a map provided by a platform-specific service. |
| MapSpan | A circular region on a Xamarin.Forms.Maps.Map. |
| MapType | Enumeration that specifies the display style of the map. |
| Pin | A marker on a Xamarin.Forms.Maps.Map. |
| PinType | Enumeration specifying the various kinds of Xamarin.Forms.Map.Pin. |
| Position | A struct that has a latitude and longitude, stored as doubles. |