本文整理汇总了C#中MKMapView类的典型用法代码示例。如果您正苦于以下问题:C# MKMapView类的具体用法?C# MKMapView怎么用?C# MKMapView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MKMapView类属于命名空间,在下文中一共展示了MKMapView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetViewForAnnotation
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation)
{
var pin = (MKAnnotationView)mapView.DequeueReusableAnnotation("zombie");
if (pin == null)
{
pin = new MKAnnotationView(annotation, "zombie");
pin.Image = UIImage.FromFile("zombie.png");
pin.CenterOffset = new PointF(0, -30);
}
else
{
pin.Annotation = annotation;
}
var zombieAnnotation = (ZombieAnnotation) annotation;
if (zombieAnnotation.Zombie.IsMale)
{
//pin.PinColor = MKPinAnnotationColor.Purple;
}
else
{
//pin.PinColor = MKPinAnnotationColor.Red;
}
return pin;
}
示例2: ViewDidLoad
public override void ViewDidLoad()
{
var mapView = new MKMapView();
mapView.Delegate = new MyDelegate();
View = mapView;
base.ViewDidLoad();
// ios7 layout
if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
EdgesForExtendedLayout = UIRectEdge.None;
var secondViewModel = (SecondViewModel)ViewModel;
var hanAnnotation = new ZombieAnnotation(secondViewModel.Han);
mapView.AddAnnotation(hanAnnotation);
mapView.SetRegion(MKCoordinateRegion.FromDistance(
new CLLocationCoordinate2D(secondViewModel.Han.Location.Lat, secondViewModel.Han.Location.Lng),
20000,
20000), true);
var button = new UIButton(UIButtonType.RoundedRect);
button.Frame = new RectangleF(10, 10, 300, 40);
button.SetTitle("move", UIControlState.Normal);
Add(button);
var set = this.CreateBindingSet<SecondView, Core.ViewModels.SecondViewModel>();
set.Bind(hanAnnotation).For(a => a.Location).To(vm => vm.Han.Location);
set.Bind(button).For("Title").To(vm => vm.Han.Location);
set.Apply();
}
示例3: ViewDidLoad
public override void ViewDidLoad()
{
_map = new MKMapView();
foreach(BusStop busStop in _busStops)
{
AddBusStopToMap(_map, busStop);
}
AddBusStopToMap(_map, _busStops[0]);
_map.ShowsUserLocation = true;
_map.Frame = new RectangleF (0, 0, this.View.Bounds.Width, this.View.Bounds.Height);
if(_busStops.Length <= 1)
{
_map.Region = new MKCoordinateRegion(FindCentre(_busStops), new MKCoordinateSpan(0.005, 0.0005));
}
else
{
_map.Region = RegionThatFitsAllStops(_busStops);
}
this.View.AddSubview (_map);
}
示例4: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Title = "MapView";
mapView = new MKMapView(View.Bounds);
mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
//mapView.MapType = MKMapType.Standard; // this is the default
//mapView.MapType = MKMapType.Satellite;
//mapView.MapType = MKMapType.Hybrid;
View.AddSubview(mapView);
// create our location and zoom
//CLLocationCoordinate2D coords = new CLLocationCoordinate2D(40.77, -73.98); // new york
//CLLocationCoordinate2D coords = new CLLocationCoordinate2D(33.93, -118.40); // los angeles
//CLLocationCoordinate2D coords = new CLLocationCoordinate2D(51.509, -0.1); // london
CLLocationCoordinate2D coords = new CLLocationCoordinate2D(48.857, 2.351); // paris
MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude));
// set the coords and zoom on the map
mapView.Region = new MKCoordinateRegion(coords, span);
}
示例5: GetViewForAnnotation
MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
MKAnnotationView annotationView = null;
if (annotation is MKUserLocation)
return null;
var anno = annotation as MKPointAnnotation;
var customPin = GetCustomPin(anno);
if (customPin == null)
{
throw new Exception("Custom pin not found");
}
annotationView = mapView.DequeueReusableAnnotation(customPin.Id);
if (annotationView == null)
{
annotationView = new CustomMKAnnotationView(annotation, customPin.Id);
annotationView.Image = UIImage.FromFile("pin.png");
annotationView.CalloutOffset = new CGPoint(0, 0);
annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("monkey.png"));
annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
((CustomMKAnnotationView)annotationView).Id = customPin.Id;
((CustomMKAnnotationView)annotationView).Url = customPin.Url;
}
annotationView.CanShowCallout = true;
return annotationView;
}
示例6: Initialize
private void Initialize ()
{
Title = Locale.GetText ("");
_mapView = new MKMapView ();
_mapView.AutoresizingMask = UIViewAutoresizing.All;
_mapView.MapType = MKMapType.Standard;
_mapView.ShowsUserLocation = true;
_sgMapType = new UISegmentedControl ();
_sgMapType.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
_sgMapType.Opaque = true;
_sgMapType.Alpha = 0.75f;
_sgMapType.ControlStyle = UISegmentedControlStyle.Bar;
_sgMapType.InsertSegment ("Map", 0, true);
_sgMapType.InsertSegment ("Satellite", 1, true);
_sgMapType.InsertSegment ("Hybrid", 2, true);
_sgMapType.SelectedSegment = 0;
_sgMapType.ValueChanged += (s, e) => {
switch (_sgMapType.SelectedSegment) {
case 0:
_mapView.MapType = MKMapType.Standard;
break;
case 1:
_mapView.MapType = MKMapType.Satellite;
break;
case 2:
_mapView.MapType = MKMapType.Hybrid;
break;
}
};
}
示例7: GetViewForAnnotation
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
// try and dequeue the annotation view
MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier);
// if we couldn't dequeue one, create a new one
if (annotationView == null)
annotationView = new MKPinAnnotationView(annotation, annotationIdentifier);
else // if we did dequeue one for reuse, assign the annotation to it
annotationView.Annotation = annotation;
// configure our annotation view properties
annotationView.CanShowCallout = true;
(annotationView as MKPinAnnotationView).AnimatesDrop = true;
(annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red;
annotationView.Selected = true;
Assembly ass = this.GetType ().Assembly;
var annotationImage =
UIImage.FromBundle((annotation as BasicPinAnnotation).ImageAdress);
annotationView.LeftCalloutAccessoryView = new UIImageView(
ResizeImage.MaxResizeImage(annotationImage,(float)40,(float)20));
return annotationView;
}
示例8: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
FoundCoords += (object sender, CoordEventArgs e) => {
storageScreenContent.SetCoords(e.Latitude,e.Longitude);
};
map = new MKMapView (UIScreen.MainScreen.Bounds);
View = map;
// create search controller
searchBar = new UISearchBar (new RectangleF (0, 0, View.Frame.Width, 50)) {
Placeholder = "Enter a search query"
};
searchController = new UISearchDisplayController (searchBar, this);
searchController.Delegate = new SearchDelegate (map);
SearchSource source = new SearchSource (searchController, map);
searchController.SearchResultsSource = source;
source.FoundCoords += (object sender, CoordEventArgs e) => {
var handler = FoundCoords;
if(handler != null){
handler(this,e);
}
this.DismissViewController(true,null);
};
View.AddSubview (searchBar);
}
示例9: GetViewForAnnotation
UIButton detailButton; // need class-level ref to avoid GC
/// <summary>
/// This is very much like the GetCell method on the table delegate
/// </summary>
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
{
// try and dequeue the annotation view
MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier);
// if we couldn't dequeue one, create a new one
if (annotationView == null)
annotationView = new MKPinAnnotationView(annotation, annotationIdentifier);
else // if we did dequeue one for reuse, assign the annotation to it
annotationView.Annotation = annotation;
// configure our annotation view properties
annotationView.CanShowCallout = true;
(annotationView as MKPinAnnotationView).AnimatesDrop = true;
(annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green;
annotationView.Selected = true;
// you can add an accessory view, in this case, we'll add a button on the right, and an image on the left
detailButton = UIButton.FromType(UIButtonType.DetailDisclosure);
detailButton.TouchUpInside += (s, e) => {
var c = (annotation as MKAnnotation).Coordinate;
new UIAlertView("Annotation Clicked", "You clicked on " +
c.Latitude.ToString() + ", " +
c.Longitude.ToString() , null, "OK", null).Show();
};
annotationView.RightCalloutAccessoryView = detailButton;
annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("Images/Icon/29_icon.png"));
//annotationView.Image = UIImage.FromBundle("Images/Apress-29x29.png");
return annotationView;
}
示例10: GetViewForAnnotation
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation)
{
var extendedAnnotation = annotation as ExtendedMapAnnotation;
if (extendedAnnotation == null) return null;
// try and dequeue the annotation view
var annotationView = mapView.DequeueReusableAnnotation(AnnotationIdentifier);
// if we couldn't dequeue one, create a new one
if (annotationView == null)
{
annotationView = new MKAnnotationView(extendedAnnotation, AnnotationIdentifier);
}
else // if we did dequeue one for reuse, assign the annotation to it
annotationView.Annotation = extendedAnnotation;
// configure our annotation view properties
annotationView.CanShowCallout = false;
annotationView.Selected = true;
if (!string.IsNullOrEmpty(extendedAnnotation.PinIcon))
{
annotationView.Image = UIImage.FromFile(extendedAnnotation.PinIcon);
}
return annotationView;
}
示例11: MapController
public MapController(Entity entity)
{
try {
Entity = entity;
Title = Entity.EntityTypeName;
_map = new MKMapView ();
_pin = new Pin(Entity);
_map.Frame = View.Bounds;
_map.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
_map.AddAnnotation(_pin);
_map.Region = new MKCoordinateRegion (_pin.Coordinate, new MKCoordinateSpan (0.01, 0.01));
View.AddSubview (_map);
_map.SelectAnnotation(_pin, true);
} catch (Exception error) {
Log.Error (error);
}
}
示例12: ViewDidLoad
public override void ViewDidLoad()
{
var mapView = new MKMapView();
View = mapView;
base.ViewDidLoad();
var firstViewModel = (FourthViewModel)ViewModel;
_regionManager = new RegionManager(mapView);
var button = new UIButton(UIButtonType.RoundedRect);
button.Frame = new RectangleF(10, 10, 300, 40);
button.SetTitle("move", UIControlState.Normal);
Add(button);
var lat = new UITextField(new RectangleF(10, 50, 130, 40));
lat.KeyboardType = UIKeyboardType.DecimalPad;
Add(lat);
var lng = new UITextField(new RectangleF(160, 50, 130, 40));
lng.KeyboardType = UIKeyboardType.DecimalPad;
Add(lng);
var set = this.CreateBindingSet<FourthView, Core.ViewModels.FourthViewModel>();
set.Bind(button).To(vm => vm.UpdateCenterCommand);
set.Bind(lat).To(vm => vm.Lat);
set.Bind(lng).To(vm => vm.Lng);
set.Bind(_regionManager).For(r => r.Center).To(vm => vm.Location);
set.Apply();
}
示例13: CreateMapView
void CreateMapView()
{
_mapView = new MKMapView (UIScreen.MainScreen.Bounds);
_mapView.ShowsUserLocation = true;
_mapView.Delegate = new MapViewDelegate ();
View.InsertSubview (_mapView, 0);
}
示例14: GetViewForAnnotation
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
{
MKAnnotationView anView;
if (annotation is MKUserLocation)
return null;
if (annotation is MonkeyAnnotation) {
// show monkey annotation
anView = mapView.DequeueReusableAnnotation (mId);
if (anView == null)
anView = new MKAnnotationView (annotation, mId);
anView.Image = UIImage.FromFile ("monkey.png");
anView.CanShowCallout = true;
anView.Draggable = true;
anView.RightCalloutAccessoryView = UIButton.FromType (UIButtonType.DetailDisclosure);
} else {
// show pin annotation
anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation (pId);
if (anView == null)
anView = new MKPinAnnotationView (annotation, pId);
((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Green;
anView.CanShowCallout = true;
}
return anView;
}
示例15: GetViewForAnnotation
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation)
{
MKAnnotationView annotationView = null;
MKPointAnnotation anno = null;
if (annotation is MKUserLocation) {
return null;
} else {
anno = annotation as MKPointAnnotation;
}
string identifier = GetIdentifier (anno);
if (identifier == "")
throw new Exception ("No Identifier found for pin");
annotationView = mapView.DequeueReusableAnnotation (identifier);
if (annotationView == null)
annotationView = new CustomMKPinAnnotationView (annotation, identifier);
//This removes the bubble that pops up with the title and everything
((CustomMKPinAnnotationView)annotationView).FormsIdentifier = identifier;
annotationView.CanShowCallout = false;
return annotationView;
}