Map annotation pin with using photo - ios

I'm confused with annotation's image view.
I've tried this:
how can I show an image in map pin annotation?
My map view can do what's shown in the first picture in that question.
Now I'm trying to do what's shown in the second picture.
Here is the question:
When I'm taking a photo, my map view will also create a pin with photo I've just taken.
How can get it?
I want let leftCalloutAccessoryView load image from iphone's camera library.
Here's my code for viewForAnnotation:
static NSString *identifier = #"MyLocation";
if ([annotation isKindOfClass:[MPViewPlaceMark class]]) {
MKPinAnnotationView *annotationView =
(MKPinAnnotationView *)[MapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"LeftIconImage.png"]];
annotationView.leftCalloutAccessoryView = leftIconView;
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
return annotationView;
}

Related

Custom marker icon iOS bad quality

I'm trying to add an image to the marker. How to achieve the best quality? As you can see the Google Map yourself increases it twice.
do you add an asset to you project or just one image?
So, you need to add asset of images (named like - bigMarker.png, bigMarker#2x.png, bigMarker#3x.png) to your project asset, like on screenshots. That works fine on iOS 9.
And that my sample of code in viewDidLoad:
// Add custom position in Kansas
CustomAnnotation *annotation = [CustomAnnotation new];
annotation.title = #"Elevation Burger";
annotation.subtitle = #"The best buns...";
annotation.coordinate = CLLocationCoordinate2DMake(39.0119020f,-98.4842460f);
[self.myMap addAnnotation:annotation];
And this one in delegate:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKAnnotationView *annotationView = nil;
if (annotation != mapView.userLocation) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:nil];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:#"bigMarker"];
annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"burgerBitmap"]];
UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImage *disclosureButtonImage = [[UIImage imageNamed:#"disclosure"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[accessoryButton setImage:disclosureButtonImage forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = accessoryButton;
}
return annotationView;
}

how to change user location pin image in mkmapview type=satellite?

In MKMapView I am having two type of map that is MKMapTypeStandard and MKMapTypeSatellite. I want to replace user location pin to another(location.jpg) image.
The pin image is changing in MKMapTypeStandard (location.jpg) but in MKMapTypeSatellite(default image) pin image displayed as default map pin image. how can i solve this problem in project?
Here is my code.
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:nil];
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
//customPinView.image = [UIImage imageNamed:#"mappin4"];
if (!pinView)
{
if (annotation == mapView.userLocation)
{
customPinView.image = [UIImage imageNamed:#"mappin4"];
}
else
{
}
customPinView.animatesDrop = NO;
customPinView.canShowCallout = NO;
customPinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return customPinView;
} else
{
pinView.annotation = annotation;
}
Try like this ;
- (void) changeMapType: (id)sender
{
if (mapView.mapType == MKMapTypeStandard)
mapView.mapType = MKMapTypeSatellite;
else
mapView.mapType = MKMapTypeStandard;
}
So by default if you use google maps, it is in the form of MKMapTypeStandard.
you can change if you want by mapView.mapType = MKMapTypeSatellite;
you can also check following url ;
Why does a custom MKMapView annotation image disappear on touch?
Make sure you're using MKAnnotationView instead of MKPinAnnotationView everywhere in your viewForAnnotation method.

How can i change mapkit annotation detail view background color?

Hi am trying to change the annotation detail view(show in map image) into a custom design like the second image.
How can i change that background image and all?
my current code is
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
mapView.showsUserLocation = YES;
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString *identifier = #"myAnnotation";
MKPinAnnotationView * annotationView = (MKPinAnnotationView*)[_MAPVIEW dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.pinColor = MKPinAnnotationColorPurple;
annotationView.canShowCallout = YES;
}else {
annotationView.annotation = annotation;
}
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:#selector(showDetailView) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = infoButton;
UIImageView *imageV=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#"pin.png"]];
annotationView.leftCalloutAccessoryView=imageV;
return annotationView;
}
current annotation detail view design(when i click on pin then i can see the annotation detail view )
but i want something like this design
please help me.

Map Annotation Adding Image

Below, I have created an Annotation for my map which works perfectly and shows up with the title and subtitle as it should.
But I wish to add a small image to the left of the annotation but can't figure out what I need to do to the below code to make it work.
// Annotation
CLLocationCoordinate2D poseLocation;
poseLocation.latitude = POSE_LATITUDE;
poseLocation.longitude = POSE_LONGITUDE;
Annotation *myAnnotation = [[Annotation alloc] init];
myAnnotation.coordinate = poseLocation;
myAnnotation.title = #"Pose Beauty Salon";
myAnnotation.subtitle = #"100, Moneyhaw Road";
[self.myMapView addAnnotation:myAnnotation];
You will need to set the delegate of your myMapView first and implement the viewForAnnotation delegate method.
There you will return MKAnnotationView instance which has a property leftCalloutAccessoryView:
The view to display on the left side of the standard callout bubble.
The default value of this property is nil. The left callout view is
typically used to display information about the annotation or to link
to custom information provided by your application. The height of your
view should be 32 pixels or less.
In the leftCalloutAccessoryView, you can assign your image there. For example:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.myMapView dequeueReusableAnnotationViewWithIdentifier:#"annotation"];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"annotation"];
UIImageView *imageView = //initialize your image view here
annotationView.leftCalloutAccessoryView = imageView;
}
annotationView.annotation = annotation;
return annotationView;
}
PS: Apparently you have asked similar question before here: Add image to the left of my annotations. I am not sure you need to post another question. Please try to implement this first.
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"current"];
myImage = [UIImage imageNamed:imagename];
CGRect cropRect = CGRectMake(0.0, 0.0,35.0, 35.0);
myImageView = [[UIImageView alloc] initWithFrame:cropRect];
myImageView.clipsToBounds = YES;
myImageView.image = myImage;
MyPin.leftCalloutAccessoryView =myImageView;
MyPin.highlighted=YES;
MyPin.canShowCallout=YES;
return MyPin;
}
It works for me , try this one

UserLocation Image doesn't move

I dont understand why the userLocation doesnt move when i set a costum image on it.
If i don't set an image, it uses the default pin blue and it works; i can see the userlocation moves when the postion changes.
here is my viewForAnnotation taken from an other post.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString* AnnotationIdentifier = #"Annotation";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mk dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (!pinView)
{
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop = NO;
pinView.canShowCallout = YES;
}
else
{
pinView.annotation = annotation;
}
if (annotation == mk.userLocation)
pinView.image = [UIImage imageNamed:#"PositionPin.png"];
else
pinView.image = [UIImage imageNamed:#"PositionPin.png"];
return pinView;
}
This appears to be a bug in the map view (still present in iOS 6) where the user location coordinates no longer update when a custom annotation view is used (even though documentation suggests it will work).
A workaround is to use Core Location to get user location updates and create your own annotation (instead of using the map view's userLocation) and then supplying a custom image for it in viewForAnnotation.
See the answer to Custom Annotation view for userlocation not moving the mapview for more details and some sample code to implement the workaround.
In addition, note that when using a custom image for your annotation view, you should use MKAnnotationView instead of MKPinAnnotationView.
When using MKPinAnnotationView, it sometimes shows its default pin image instead of your custom image.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString* AnnotationIdentifier = #"Annotation";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mk dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (!pinView)
{
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop = NO;
pinView.canShowCallout = YES;
}
pinView.annotation = annotation;
pinView.image = [UIImage imageNamed:#"PositionPin.png"];
return pinView;
}

Resources