Last active
August 29, 2015 14:02
-
-
Save ajonno/bb081a1c2239d357e0ac to your computer and use it in GitHub Desktop.
Xamarin - basic map creation + current location + set a pin + zoom level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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