react-native-yandex-map-kit
This is a wrapper around Yandex Map Kit for iOS and Android.
Since original projects are in deep coma, here I only support features that I needed for my other projects. If you need markers, callouts or polygons, I suggest you use react-native-maps. However, if you must use yandex map kit in your react-native projects and you need any of these features, I encourage you to contribute. Just be sure to check out both of the original SDKs before you implement anything, because they are quite different!
Note that Android version might not work properly on emulators, which results in map tiles not being rendered.
Installation
$ npm install react-native-yandexmapkit --save
Android
-
Run
react-native link
-
Add following permissions to your
android/app/src/AndroidManifest.xml
:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" />
-
Add yandexmapkit-android repo to your
android/build.gradle
:allprojects { repositories { ... maven { url 'https://github.com/yandexmobile/yandexmapkit-android/raw/maven/' } } }
iOS
-
This module requires CocoaPods to be used in iOS project. To add CocoaPods to your React Native project, follow steps 2 throught 7 of this tutorial. Add this line
pod 'react-native-yandexmapkit', :path => '../node_modules/react-native-yandexmapkit'
to your Podfile (you may need to adjust path if you have non-standard project structure). And then run
pod install
(if you’re setting up Cocoapods for the first time) orpod update
(if you’re adding MoPub to an existing CocoaPods project). -
Add
NSLocationWhenInUseUsageDescription
key inInfo.plist
if you want to display user's location. -
Make sure that yandex maps can download stuff by configuring App Transport Security
Usage
-
You'll need Yandex Map Kit API key. To obtain it, you need to send e-mail to Yandex support. You can find more info on this here: EN, RU.
-
import { YandexMapKit, YandexMapView } from 'react-native-yandexmapkit';
-
Make sure to call
YandexMapKit.setApiKey(YANDEXMAPKIT_API_KEY);
before mountingYandexMapView
component. -
Render
YandexMapView
component:<YandexMapView ref="yandexMap" onInteraction={this.onInteraction} region={this.state.region} showMyLocation={true} geocodingEnabled={true} onGeocoding={this.onGeocoding} showMyLocationButton={true}/>
Component API
Props
Prop | Type | Default | Description |
---|---|---|---|
region |
Object |
The region to be displayed by the map. The region is defined by the center coordinates and the span of coordinates to display: {latitude, longitude, latitudeDelta, longitudeDelta} |
|
initialRegion |
Object |
The initial region to be displayed by the map. Use this prop instead of region only if you don't want to control the viewport of the map besides the initial region.Changing this prop after the component has mounted will not result in a region change. This is similar to the initialValue prop of a text input. |
|
showMyLocation |
Boolean |
false |
If true the map will show current user location marker. |
nightMode |
Boolean |
false |
A Boolean indicating whether the map should be rendered in a night mode. |
showsTraffic |
Boolean |
false |
A Boolean value indicating whether the map displays traffic information. |
geocodingEnabled |
Boolean |
false |
A Boolean value indicating whether the should send reverse geocoding reqquests when region changes. These requests will return the description of geo object found in the center of the map. |
disableAndroidGeocoding |
Boolean |
false |
If true , all reverse geocoding requests will be sent from JS. Otherwise, Android will use its own implementation. |
geocodingApiKey |
String |
Yandex Maps API key to be used in geocoding requests, can be obtained here. This key is different from Yande Map KIt API key. | |
geocodingOptions |
Object |
{ sco: 'latlong', kind: 'house' } |
Reverse geocoding request parameters |
showMyLocationButton |
Boolean |
false |
If true , renders show my location button in top-right corner of the map |
myLocationButtonPosition |
Style |
{ position: 'absolute', top: 16, right: 16, } | Style used to position container view with 'show my location' button inside it |
renderMyLocationButton |
Function |
Use this to render custom 'show my location' button |
Android-only props
The component exposes some Android-only props that control map UI:
- showBuiltInScreenButtons: PropTypes.bool,
- showFindMeButton: PropTypes.bool,
- showJamsButton: PropTypes.bool,
- showScaleView: PropTypes.bool,
- showZoomButtons: PropTypes.bool,
- interactive: PropTypes.bool,
- hdMode: PropTypes.bool,
Events
Event Name | Returns | Notes |
---|---|---|
onInteraction |
{latitude, longitude, latitudeDelta, longitudeDelta, type} |
Fired when user interacts with map. |
On Android, interaction type is returned in type attribute, list of types can be found here | ||
On iOS, this event is fired only at the end of interaction. | ||
onGeocoding |
Objects | Takes two arguments: the first one is in native Android format, the second one is full response from web service. |
Methods
Method Name | Arguments | Notes |
---|---|---|
animateToCoordinate |
PropTypes.shape({latitude: PropTypes.number, longitude: PropTypes.number}) |
Animates map to given coordinate, or to user's current position if argument is undefined. |
YandexMapKit API
Method Name | Arguments | Notes |
---|---|---|
setApiKey |
String | Sets Yandex Map Kit API key for all map views you use. Call this before you mount your first map view. |
requestGeocoding |
geocode: string, Required options: object, apikey: string |
Helper method to call Yandex Geocoder, takes three arguments: geocode - queried address string or coordinate, options -well, options apikey - Yandex Maps API key for geocoding requests, this is different from Yandex Map Kit key Returns Promise which resolves with json |
makeDebouncedGeocoding |
options: object onComplete: function apiKey: string debounceWait: number |
Convenience method to make Yandex Geocoder requests. options - geocoder request options onComplete - will be called with geocoder two arguments - first match in Android format, and full response apiKey - same as for requestGeocoding debounceWait - debouncing interval, defaults to 150 ms Depending on options returns function that takes one argument - address, or two arguments - latitude and longitude (for reverse geocoding). |
Example
You can find it here
You'll need to create .env.development
property file in example
dir and put your YANDEXMAPKIT_API_KEY
in it.