want to show this kind on pin on google map, how to achieve this.
From the Documentation:
Change the default marker icon
If you want to change the default marker image you can set a custom
icon. Custom icons are always set as a UIImage object. The following
snippet creates a marker with a custom icon centered at London,
England. The snippet assumes that your application contains an image
named "house.png".
For more:
OBJECTIVE-C
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
GMSMarker *london = [GMSMarker markerWithPosition:position];
london.title = #"London";
london.icon = [UIImage imageNamed:#"house"];
london.map = mapView_;
I had to do something similar for selected and unselected markers. But the idea is still the same with what you want to do.
Assuming you have a parkingObject model, when plotting the markers:
-(void) plotMarkers{
for (ParkingObject *parkingMarker in parkingArray){
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = parkingMarker.position;
marker.userData = parkingMarker;
marker.icon = [self createMarker:marker withImageName:#"markerIcon.png"];
marker.infoWindowAnchor = CGPointMake (0.5, 1);
marker.map = mapView_;
}
}
create custom marker with a different image and data:
- (UIImage*) createMarker: (GMSMarker* )marker withImageName:(NSString* )imageName{
ParkingObject *parkingObject = marker.userData;
if([imageName isEqualToString:#"markerSelected.png"]){
MarkerSelected * infoWindow = [[[NSBundle mainBundle]loadNibNamed:#"MarkerSelected" owner:self options:nil]objectAtIndex:0];
infoWindow.markerImage.image = [UIImage imageNamed:imageName];
return [self imageFromView:infoWindow];
}
else{
Marker * infoWindow = [[[NSBundle mainBundle]loadNibNamed:#"Marker" owner:self options:nil]objectAtIndex:0];
infoWindow.priceLabel.text = [NSString stringWithFormat:#"$%.0f",parkingObject.rate.floatValue];
infoWindow.markerImage.image = [UIImage imageNamed:imageName];
return [self imageFromView:infoWindow];
}
}
You'll need to create a marker.xib that has the images/icon/text properties that you can set
this is just sample code, you'll need to customize it for your needs.
Related
I'm use button for adding pin on specific location and my map already load and showing on screen. then press button not response even marker create and assign coordinates as well.
-(IBAction)addingMarkerOnMap:(id)sender
{
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
GMSMarker *london = [GMSMarker markerWithPosition:position];
london.title = #"London";
london.icon = [UIImage imageNamed:#"Standard"];
london.map = self.mapView;
}
Try this code:
-(IBAction)addingMarkerOnMap:(id)sender
{
dispatch_async(dispatch_get_main_queue(), ^{
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
GMSMarker *london = [GMSMarker markerWithPosition:position];
london.title = #"London";
london.icon = [UIImage imageNamed:#"Standard"];
london.map = self.mapView;
});
}
I want to add new GMSMarker in the map and remove the old one. Previously I was using [map clear]; method and adding new marker. It was working fine. But I dont want that. I want to add new marker and remove the old marker without clearing the map each time.
My code:
if(markerMYLocation == nil)
{
markerMYLocation = [[GMSMarker alloc] init];
}
markerMYLocation.map = nil;
markerMYLocation.position = CLLocationCoordinate2DMake(latitude_Point, longitude_Point);
markerMYLocation.title = #"You";
markerMYLocation.groundAnchor = CGPointMake(0.5, 0.5);
markerMYLocation.icon = [UIImage imageNamed:#"white.png"];
markerMYLocation.map = mapViewGoog;
Question:
1) What is the correct way of removing and adding the marker?
2)I am initializing marker only in my viewDidLoad. Is that the correct way of doing this or should I initialize each time I add it?
Marker add on Map View
GMSMarker *marker = [GMSMarker markerWithPosition:[marker.getcoordinateObject MKCoordinateValue]];
marker.icon =[UIImage imageNamed:#“”];
marker.title = #“Driver Pin”
marker.map = mapView_;
[allMarkeronMap addObject:googleMapsDriverPin]; // Add maker on Array
[_mapView addSubview:mapView_];
//Make MutableArray on viewDidLoad
NSMutableArray * allMarkeronMap =[NSMutableArray alloc] init];
particualr marker or old marker remove on mapView
for (GMSMarker *pin in allMarkeronMap) {
if (pin.userData == #"Driver Pin"){
pin.map = nil;
}
}
I have implemented GMSMarker, in that my end point GMSMarker do not show on google map view.
- (GMSMarker *)markerWithPath:(CLLocationCoordinate2D *)path Index:(NSUInteger )index IconName:(NSString *)imageName {
GMSMarker *marker = [GMSMarker markerWithPosition:path[index]];
marker.icon = [UIImage imageNamed:imageName];
marker.flat = YES;
return marker;
}
I'm new to iPhone development, in my application I want to draw route between two points and show the multiple markers on my route. Now I'm done with the Route between two points but I don't know how to draw multiple markers on my route. So please help me to do this.
Thanks in Advance!!!
_markerStart = [GMSMarker new];
_markerStart.title = [[[routeDict objectForKey:#"legs"] objectAtIndex:0]objectForKey:#"start_address"];
_markerStart.icon = newImage; //[UIImage imageNamed:#"startMarker.png"];
_markerStart.map = gmsMapView;
_markerStart.position = startPoint;
_markerFinish = [GMSMarker new];
_markerFinish.title = [[[routeDict objectForKey:#"legs"] objectAtIndex:0]objectForKey:#"end_address"];
_markerFinish.icon = newImage; //[UIImage imageNamed:#"finishMarker.png"];
_markerFinish.map = gmsMapView;
_markerFinish.position = endPoint;
Here I have added start and end marker.
As you are completed with drawing route between two points, you will have co-ordinates for route. You can take some co-ordinates from those and draw them on Google Maps.
For drawing route you may have used GMSPolyline. For polyline, you must have used GMSPath. From path you can get co-ordinates by using method
-(CLLocationCoordinate2D)coordinateAtIndex:(NSUInteger)index
GMSPath Doc
You can use these co-ordinates to plot the marker on route. GMSMarkers Doc
Check this code (here gmsPath as GMSPath) EDIT:
//GMSPath *gmsPath;
//NSString *title;
for (int i = 0; i < [gmsPath count]; i++) {
CLLocationCoordinate2D location = [gmsPath coordinateAtIndex: i];
GMSMarker *marker = [GMSMarker markerWithPosition:location];
marker.title = title;
marker.icon = [UIImage imageNamed:#"marker_img.png"];
marker.map = self.mapView;
}
This will plot marker for each co-ordinate.
Using Google maps iOS SDK I have implemented a mapView
in that i have created markers as follows
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.icon = [UIImage imageNamed:#"point1.png"];
marker.map = mapView_;
But i need to Display animated images ie some sequence of images to display, animated rings around a point, instead of original GMSMarker
sequence of images are point1.png point2.png point3.png point4.png point5.png
Can any one help me to achieve this
in
- (RMMapLayer *)mapView:(RMMapView *)mpView layerForAnnotation:(RMAnnotation *)annotation
{
UIImageView *pulseRingImg = [[UIImageView alloc] initWithFrame: CGRectMake(-30, -30, 78, 78)];
pulseRingImg.image = [UIImage imageNamed:#"PulseRing.png"];
pulseRingImg.userInteractionEnabled = NO;
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:#"transform.scale.xy"];
theAnimation.duration=2.0;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.autoreverses=NO;
pulseRingImg.alpha=0;
theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
theAnimation.toValue=[NSNumber numberWithFloat:1.0];
pulseRingImg.alpha = 1;
[pulseRingImg.layer addAnimation:theAnimation forKey:#"pulse"];
pulseRingImg.userInteractionEnabled = NO;
[mapView addSubview:pulseRingImg];
[marker addSublayer:pulseRingImg.layer];
return marker;
}
PulseRing.png in [UIImage imageNamed:#"PulseRing.png"] is
Getting reference from:
ios - how to do a native "Pulse effect" animation on a UIButton
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:#"opacity"];
theAnimation.duration=1.0;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.0];
[myButton.layer addAnimation:theAnimation forKey:#"animateOpacity"];
From the google map sdk / it appears at this moment v1.9 the only supported animations in using framed based images. If you're using mapkit - > you can simply use https://github.com/TransitApp/SVPulsingAnnotationView
From google's sdk -> ios sample
AnimatedCurrentLocationViewController.m
NSMutableArray *frames = [NSMutableArray array];
for (int i =0; i<146; i++) {
NSString *img = [NSString stringWithFormat:#"pulse-%d",i];
[frames addObject:[UIImage imageNamed:img]];
}
marker.icon = [UIImage animatedImageWithImages:frames duration:3];
On my branch of FlipBook https://github.com/johndpope/Flipbook I've rendered out the pulse animations in retina to a bunch of transparent png images. It maybe possible to further reduce these file sizes in photoshop. Granted this is not ideal and will cause your binary file size to be bloated but is passable.
Have you tried this?
https://github.com/shu223/Pulsator
Initiate and add to your view's layer, then call start!
let pulsator = Pulsator()
view.layer.addSublayer(pulsator)
pulsator.start()
For SWIFT 3:
You can use UIImage.animatedImage for your marker´s icon, like this:
Create an array of UIImage with the different images
let image1 = UIImage(named: "marker-image-1")
let image2 = UIImage(named: "marker-image-2")
let image3 = UIImage(named: "marker-image-3")
let imagesArray = [image1,image2,image3]
Set your marker´s icon:
marker.icon = UIImage.animatedImage(with: imagesArray as! [UIImage], duration: 1.2)
marker.map = mapView
You can change the duration of the animation
Run your app, you will see the marker animated with the different images
You can customize your marker by changing the marker icon property.
eg:
london.icon = [UIImage imageNamed:#"house"];
you can give your own image or some edited image there.
if you want to customize the infowindow that will be displayed after you clicked on a marker.
refer that link
https://developers.google.com/live/shows/864758637