Skip to content

Commit f59feb3

Browse files
Merge pull request react-native-maps#1049 from pyliaorachel/master
Issue react-native-maps#934 Add customized user location annotation text
2 parents 5766ab2 + 4cd320b commit f59feb3

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

components/MapView.js

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ const propTypes = {
8686
*/
8787
showsUserLocation: PropTypes.bool,
8888

89+
/**
90+
* The title of the annotation for current user location. This only works if
91+
* `showsUserLocation` is true.
92+
* There is a default value `My Location` set by MapView.
93+
*
94+
* @platform ios
95+
*/
96+
userLocationAnnotationTitle: PropTypes.string,
97+
8998
/**
9099
* If `false` hide the button to move map to the current user's location.
91100
* Default value is `true`.

docs/mapview.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| `mapType` | `String` | `"standard"` | The map type to be displayed. <br/><br/> - standard: standard road map (default)<br/> - satellite: satellite view<br/> - hybrid: satellite view with roads and points of interest overlayed<br/> - terrain: (Android only) topographic view
1212
| `customMapStyle` | `Array` | | Adds custom styling to the map component. See [README](https://github.com/airbnb/react-native-maps#customizing-the-map-style) for more information.
1313
| `showsUserLocation` | `Boolean` | `false` | If `true` the app will ask for the user's location. **NOTE**: You need to add `NSLocationWhenInUseUsageDescription` key in Info.plist to enable geolocation, otherwise it is going to *fail silently*!
14+
| `userLocationAnnotationTitle` | `String` | | The title of the annotation for current user location. This only works if `showsUserLocation` is true. There is a default value `My Location` set by MapView. **Note**: iOS only.
1415
| `followsUserLocation` | `Boolean` | `false` | If `true` the map will focus on the user's location. This only works if `showsUserLocation` is true and the user has shared their location. **Note**: iOS only.
1516
| `showsMyLocationButton` | `Boolean` | `true` | If `false` hide the button to move map to the current user's location.
1617
| `showsPointsOfInterest` | `Boolean` | `true` | If `false` points of interest won't be displayed on the map.

ios/AirMaps/AIRMap.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern const CGFloat AIRMapZoomBoundBuffer;
2424
@property (nonatomic, strong) UIImageView *cacheImageView;
2525
@property (nonatomic, strong) UIView *loadingView;
2626

27+
@property (nonatomic, copy) NSString *userLocationAnnotationTitle;
2728
@property (nonatomic, assign) BOOL followUserLocation;
2829
@property (nonatomic, assign) BOOL hasStartedRendering;
2930
@property (nonatomic, assign) BOOL cacheEnabled;

ios/AirMaps/AIRMapManager.m

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ - (UIView *)view
6565
}
6666

6767
RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL)
68+
RCT_EXPORT_VIEW_PROPERTY(userLocationAnnotationTitle, NSString)
6869
RCT_EXPORT_VIEW_PROPERTY(followsUserLocation, BOOL)
6970
RCT_EXPORT_VIEW_PROPERTY(showsPointsOfInterest, BOOL)
7071
RCT_EXPORT_VIEW_PROPERTY(showsBuildings, BOOL)
@@ -491,7 +492,10 @@ - (void)mapView:(AIRMap *)mapView didSelectAnnotationView:(MKAnnotationView *)vi
491492
{
492493
if ([view.annotation isKindOfClass:[AIRMapMarker class]]) {
493494
[(AIRMapMarker *)view.annotation showCalloutView];
495+
} else if ([view.annotation isKindOfClass:[MKUserLocation class]] && mapView.userLocationAnnotationTitle != nil && view.annotation.title != mapView.userLocationAnnotationTitle) {
496+
[(MKUserLocation*)view.annotation setTitle: mapView.userLocationAnnotationTitle];
494497
}
498+
495499
}
496500

497501
- (void)mapView:(AIRMap *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
@@ -503,6 +507,10 @@ - (void)mapView:(AIRMap *)mapView didDeselectAnnotationView:(MKAnnotationView *)
503507
- (MKAnnotationView *)mapView:(__unused AIRMap *)mapView viewForAnnotation:(AIRMapMarker *)marker
504508
{
505509
if (![marker isKindOfClass:[AIRMapMarker class]]) {
510+
if ([marker isKindOfClass:[MKUserLocation class]] && mapView.userLocationAnnotationTitle != nil) {
511+
[(MKUserLocation*)marker setTitle: mapView.userLocationAnnotationTitle];
512+
return nil;
513+
}
506514
return nil;
507515
}
508516

0 commit comments

Comments
 (0)