Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

mkmapview set region without push button

$
0
0

I Got code sample about show current location,

its shows on map but not setregion and close cam without push a button.

// Show the user location this.mapView.ShowsUserLocation = true;

     // Assign a delegate object to the map view
     this.mapView.Delegate = new MapViewDelegate();


     addPin.Clicked+= delegate
     {
        CLLocationCoordinate2D mapCoordinate = this.mapView.UserLocation.Location.Coordinate;

        // Set the map region
        this.mapView.SetRegion(MKCoordinateRegion.FromDistance (mapCoordinate, 1000, 1000), true);

        // Create and add an annotation to the map
        MKPointAnnotation myAnnotation = new MKPointAnnotation();
        myAnnotation.Coordinate = mapCoordinate;
        myAnnotation.Title = "MyAnnotation";
        myAnnotation.Subtitle = "Standard annotation";

        this.mapView.AddAnnotation(myAnnotation);


     };





  }

  private class MapViewDelegate : MKMapViewDelegate
  {

     public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
     {

        // Determine the annotation we want to provide a view for.
        if (annotation is MKUserLocation)
        {

           return null;

        } else
        {

           string reuseIdentifier = "MyAnnotation";
           MKPinAnnotationView pinView = mapView.DequeueReusableAnnotation(reuseIdentifier) as MKPinAnnotationView;
           if (null == pinView)
           {

              pinView = new MKPinAnnotationView(annotation, reuseIdentifier);
              pinView.PinColor = MKPinAnnotationColor.Purple;
              pinView.AnimatesDrop = true;
              pinView.CanShowCallout = true;

           }//end if

           return pinView;

        }//end if else
     }
  }

when i add

        CLLocationCoordinate2D mapCoordinate = this.mapView.UserLocation.Location.Coordinate;

        // Set the map region
        this.mapView.SetRegion(MKCoordinateRegion.FromDistance (mapCoordinate, 1000, 1000), true);

program crashes

is it way to automaticly setregion without push button?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>