I have an application where in I give user 2 options. 1. Select your current location through GPS 2. Enter your current location manually.
What I want is When user has selected thh first option then I have to display the blue animated icon for current location And when user has selected 2nd option then I have to display my own custom icon for current location.
Is it possible? Suggestions are most welcomed.
Thanks.
First set a boolean variable for Example isInGPSMode
now apply following code
if(isInGPSMode==TRUE)
{
mapViewHome.showsUserLocation=TRUE;
}
else
{
mapViewHome.showsUserLocation=FALSE;
}
and handle the map view delegate as
- (MKAnnotationView *) mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>) annotation
{
if(annotation==mapViewHome.userLocation)
{
return nil;
}
addAnnonation *tempAnnonation=(addAnnonation *)annotation;
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorRed;
return annView;
}
for further details refer the link http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html
hope this helps
Rupesh's solution in Swift :
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
// Keep default pin for user location
if myMapView.userLocation.isEqual(annotation) {
return nil;
}
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier("pin") as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pin")
pinView!.canShowCallout = true
pinView!.animatesDrop = true
pinView!.pinColor = .Red
}
else {
pinView!.annotation = annotation
}
return pinView
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.