Skip to content

Instantly share code, notes, and snippets.

@ajonno
Last active August 29, 2015 14:02
Show Gist options
  • Save ajonno/bb081a1c2239d357e0ac to your computer and use it in GitHub Desktop.
Save ajonno/bb081a1c2239d357e0ac to your computer and use it in GitHub Desktop.
Xamarin - basic map creation + current location + set a pin + zoom level
// put a map into the View
var map = new MKMapView (UIScreen.MainScreen.Bounds);
View = map;
//allows user location to be shown on a map
map.ShowsUserLocation = true;
//get my current geo-location lat/long coordinates
var myCoord = map.UserLocation.Coordinate;
Console.WriteLine ("lat {0}, long {1}", myCoord.Latitude, myCoord.Longitude);
//puts an annotation on the point of interest geo-coordinates
map.AddAnnotation (new MKPointAnnotation () {
Title = "My annotation",
Subtitle = "the subtitle",
Coordinate = new CLLocationCoordinate2D(myCoord.Latitude,myCoord.Longitude)
});
//centers the map to designated geo-coordinates
map.CenterCoordinate = new CLLocationCoordinate2D(myCoord.Latitude,myCoord.Longitude);
//define co-ordinates and a "span" so you can zoom in to the desired level on the map
var coords = new CLLocationCoordinate2D (myCoord.Latitude,myCoord.Longitude);
MKCoordinateSpan span = new MKCoordinateSpan(0.06,0.06);
//tell the map to use the co-ordinates and span
map.Region = new MKCoordinateRegion(coords, span);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment