Dolomo KodoMo
Dolomo KodoMo

Reputation: 21

How to mkmapview get location by annotation

In my application i have used the MKmapview I want to show locations as I drag the pin to pin.

how to get location by pin? I want to show locations as I drag the pin to pin.

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
self.mapView.centerCoordinate = userLocation.coordinate;
CLLocationDistance distance = 1500;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, distance, distance);
MKCoordinateRegion adjusterRegion = [self.mapView regionThatFits:region];

[self.mapView setRegion:adjusterRegion animated:YES];

self.latitudeValue.text = [NSString stringWithFormat:@"%f",userLocation.coordinate.latitude];
self.longtitudeValue.text = [NSString stringWithFormat:@"%f",userLocation.coordinate.longitude];


custom *location = [[custom alloc] initWithTitle:@"location" subtitle:@"" location:userLocation.coordinate];
[self.mapView addAnnotation:location];

MKCoordinateRegion regions = {{0.0,0.0},{0.0,0.0}};
regions.center.latitude = 13.905726;
regions.center.longitude = 100.52142100000003;
regions.span.latitudeDelta = 0.01f;
regions.span.longitudeDelta = 0.01f;
[self.mapView setRegion:region animated:YES];

customlocation *locs = [[customlocation alloc] initWithTitle:@"test" subtitle:@"" location:regions.center];
[self.mapView addAnnotation:locs];

}


-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{


if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

static NSString *reuseId = @"pin";
MKPinAnnotationView *pa = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (pa == nil)
{
    pa = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
    pa.draggable = YES;
    pa.canShowCallout = YES;
}
else
{
    pa.annotation = annotation;
}
    return pa;
}

please help me I want to show location as I drag the pin to pin.

Upvotes: 1

Views: 805

Answers (1)

Parth Pandya
Parth Pandya

Reputation: 1490

Please check this answer, This is similar to the answer you looking for except that guy want to get coordinated where user drops the pin.

And here is the same answer for the question you asked,

Upvotes: 2

Related Questions