Skip to content

Commit 3f881ad

Browse files
author
Spike Brehm
authored
Merge pull request react-native-maps#734 from Mobeye/fix/google_maps_ios_anchor
Fix Anchor point on Google Maps iOS
2 parents 27e7fd9 + c7fe0d6 commit 3f881ad

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

docs/marker.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
| `image` | `ImageSource` | | A custom image to be used as the marker's icon. Only local image resources are allowed to be used.
1010
| `pinColor` | `Color` | | If no custom marker view or custom image is provided, the platform default pin will be used, which can be customized by this color. Ignored if a custom marker is being used.
1111
| `coordinate` | `LatLng` | | The coordinate for the marker.
12-
| `centerOffset` | `Point` | | The offset (in points) at which to display the view.<br/><br/> By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in points. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.<br/><br/> For android, see the `anchor` prop.
12+
| `centerOffset` | `Point` | | The offset (in points) at which to display the view.<br/><br/> By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in points. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.<br/><br/> For Google Maps, see the `anchor` prop.
1313
| `calloutOffset` | `Point` | | The offset (in points) at which to place the callout bubble.<br/><br/> This property determines the additional distance by which to move the callout bubble. When this property is set to (0, 0), the anchor point of the callout bubble is placed on the top-center point of the marker view’s frame. Specifying positive offset values moves the callout bubble down and to the right, while specifying negative values moves it up and to the left.<br/><br/> For android, see the `calloutAnchor` prop.
14-
| `anchor` | `Point` | | Sets the anchor point for the marker.<br/><br/> The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.<br/><br/> The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).<br/><br/> For ios, see the `centerOffset` prop.
14+
| `anchor` | `Point` | | Sets the anchor point for the marker.<br/><br/> The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.<br/><br/> The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).<br/><br/> For MapKit on iOS, see the `centerOffset` prop.
1515
| `calloutAnchor` | `Point` | | Specifies the point in the marker image at which to anchor the callout when it is displayed. This is specified in the same coordinate system as the anchor. See the `anchor` prop for more details.<br/><br/> The default is the top middle of the image.<br/><br/> For ios, see the `calloutOffset` prop.
1616
| `flat` | `Boolean` | | Sets whether this marker should be flat against the map true or a billboard facing the camera false.
1717
| `identifier` | `String` | | An identifier used to reference this marker at a later date.

ios/AirGoogleMaps/AIRGoogleMapMarker.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@property (nonatomic, copy) NSString *title;
2727
@property (nonatomic, copy) NSString *subtitle;
2828
@property (nonatomic, strong) UIColor *pinColor;
29+
@property (nonatomic, assign) CGPoint anchor;
2930
@property (nonatomic, assign) NSInteger zIndex;
3031
@property (nonatomic, assign) BOOL draggable;
3132

ios/AirGoogleMaps/AIRGoogleMapMarker.m

+6-3
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ - (void)setImageSrc:(NSString *)imageSrc
225225

226226
_iconImageView = imageView;
227227
[self iconViewInsertSubview:imageView atIndex:0];
228-
229-
// TODO: This could be a prop
230-
//_realMarker.groundAnchor = CGPointMake(0.75, 1);
231228
});
232229
}];
233230
}
@@ -253,6 +250,12 @@ - (void)setPinColor:(UIColor *)pinColor {
253250
_realMarker.icon = [GMSMarker markerImageWithColor:pinColor];
254251
}
255252

253+
- (void)setAnchor:(CGPoint)anchor {
254+
_anchor = anchor;
255+
_realMarker.groundAnchor = anchor;
256+
}
257+
258+
256259
- (void)setZIndex:(NSInteger)zIndex
257260
{
258261
_zIndex = zIndex;

ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ - (UIView *)view
3333
RCT_EXPORT_VIEW_PROPERTY(title, NSString)
3434
RCT_REMAP_VIEW_PROPERTY(description, subtitle, NSString)
3535
RCT_EXPORT_VIEW_PROPERTY(pinColor, UIColor)
36+
RCT_EXPORT_VIEW_PROPERTY(anchor, CGPoint)
3637
RCT_EXPORT_VIEW_PROPERTY(zIndex, NSInteger)
3738
RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL)
3839
RCT_EXPORT_VIEW_PROPERTY(onDragStart, RCTDirectEventBlock)

0 commit comments

Comments
 (0)