|
2 | 2 |
|
3 | 3 | Multi-platform Geocoding library for React Native apps. |
4 | 4 |
|
5 | | - |
6 | 5 | [](https://circleci.com/gh/timwangdev/react-native-geocoder-reborn/tree/master) |
7 | 6 | [](https://www.npmjs.com/package/@timwangdev/react-native-geocoder) |
8 | 7 | [](https://www.npmjs.com/package/@timwangdev/react-native-geocoder) |
9 | 8 |
|
10 | | -The project is originally forked from [devfd/react-native-geocoder](https://github.com/devfd/react-native-geocoder). Since 1.0 the project have been refactored and supports more features includes maximum results limit, search boundary and React hooks. |
| 9 | +The project is originally forked from [devfd/react-native-geocoder](https://github.com/devfd/react-native-geocoder). Since 1.0 the project have been refactored and supports more features includes web support, maximum results limit, search boundary and request headers for Google Maps API. |
11 | 10 |
|
12 | | -**Please check the [Release page](https://github.com/timwangdev/react-native-geocoder-reborn/releases/tag/v1.0.0) for Version 1.0.0 Full Changelog and Migration Guide.** |
| 11 | +**Please check the [GitHub Release page](https://github.com/timwangdev/react-native-geocoder-reborn/releases/) for Version 1.0.0 Full Changelog and Migration Guide.** |
13 | 12 |
|
14 | 13 | ## Installation |
15 | 14 |
|
@@ -113,66 +112,74 @@ try { |
113 | 112 |
|
114 | 113 | ### Geocode Address |
115 | 114 |
|
116 | | -* `Geocoder.geocodeAddress(address: string, options?: GeocoderOptions)` |
| 115 | +* __`Geocoder.geocodeAddress(address: string, options?: GeocoderOptions)`__ |
117 | 116 |
|
118 | | -* Returns `Promise<GeocodingObject[]>` |
| 117 | + * Returns `Promise<GeocodingObject[]>` |
119 | 118 |
|
120 | | -* Supports `regionIos` on iOS. |
| 119 | + * Supports `regionIos` on iOS for preferred search boundary. |
121 | 120 |
|
122 | | -* Supports `bounds` on Android and Google Maps API. |
| 121 | + * Supports `bounds` on Android and Google Maps API. |
123 | 122 |
|
124 | 123 | ### Geocode Position (Reverse Geocoding) |
125 | 124 |
|
126 | | -* `Geocoder.geocodePosition(position: { lat: number, lng: number }, options?: GeocoderOptions)` |
| 125 | +* __`Geocoder.geocodePosition(position: { lat: number, lng: number }, options?: GeocoderOptions)`__ |
127 | 126 |
|
128 | | -* Returns `Promise<GeocodingObject[]>` |
| 127 | + * Returns `Promise<GeocodingObject[]>` |
129 | 128 |
|
130 | 129 | ### `GeocoderOptions` |
131 | 130 |
|
132 | 131 | ```typescript |
133 | 132 | { |
134 | | - // Your Google Maps API key, required if when `fallbackToGoogle` or `forceGoogleOnIos` is set. Make sure Geocoding API is enabled. |
| 133 | + // Your Google Maps API key, required if `fallbackToGoogle` or `forceGoogleOnIos` is `true`. |
135 | 134 | apiKey?: string; |
136 | 135 |
|
137 | 136 | // Preferred Locale for outputs, defaults to 'en'. (See Note 1) |
138 | 137 | locale?: string; |
139 | 138 |
|
140 | | - // (Not available for Google Maps) Maximum returned results, defaults to 5 |
| 139 | + // Max number of addresses to return, defaults to 2. (See Note 2) |
141 | 140 | maxResults?: number; |
142 | 141 |
|
143 | | - // (Android and Google only) Set the bounds for address geocoding. (See Note 2) |
| 142 | + // (Android and Google only) Set the bounds for address geocoding. (See Note 3) |
144 | 143 | bounds?: { |
145 | | - sw: { lat: number, lng: number }, // Lower left corner |
146 | | - ne: { lat: number, lng: number }, // Upper right corner |
| 144 | + // Lower left corner |
| 145 | + sw: { lat: number, lng: number }, |
| 146 | + |
| 147 | + // Upper right corner |
| 148 | + ne: { lat: number, lng: number }, |
147 | 149 | }; |
148 | 150 |
|
149 | | - // (iOS native only) Set circular region for address geocoding. (See Note 2) |
| 151 | + // (iOS native only) Set circular region for address geocoding. (See Note 3) |
150 | 152 | regionIos?: { |
151 | | - center: { lat: number, lng: number }, // Center of the circular region |
152 | | - radius: number, // Radius of the circular region. Unit: km |
| 153 | + // Center of the circular region |
| 154 | + center: { lat: number, lng: number }, |
| 155 | + |
| 156 | + // Radius of the circular region. Unit: km |
| 157 | + radius: number, |
153 | 158 | };; |
154 | 159 |
|
155 | 160 | // Should use Google Maps API if native query fails, defaults to false. |
156 | 161 | fallbackToGoogle?: boolean; |
157 | 162 |
|
158 | | - // Should always use Google Maps API on iOS, defaults to false. (See Note 3) |
| 163 | + // Should always use Google Maps API on iOS, defaults to false. (See Note 4) |
159 | 164 | forceGoogleOnIos?: boolean; |
160 | 165 |
|
161 | | - // Custom headers when sending Google Maps API requests. (See Note 4) |
| 166 | + // Custom headers when sending Google Maps API requests. (See Note 5) |
162 | 167 | requestHeaders?: { [key: string]: string }; |
163 | 168 | } |
164 | 169 | ``` |
165 | 170 | #### Notes: |
166 | 171 |
|
167 | 172 | 1. Platforms may have different implantations for locale preference. Here is [Google Maps API supported language list](https://developers.google.com/maps/faq#languagesupport). |
168 | 173 |
|
| 174 | +2. Generally, only one entry will return, though the geocoder may return several results when address queries are ambiguous. Smaller numbers (1 to 5) for `maxResults` are recommended. |
| 175 | + |
169 | 176 | 2. On iOS the preferred search boundary for address geocoding only support "circular" region, while on Android and Google Maps API it using "rectangular" bounds. `regionIos` will have no effect if `forceGoogleOnIos` is `true`. |
170 | 177 |
|
171 | 178 | 3. Use `forceGoogleOnIos` if you want consistent result on both iOS and Android platform, due to the limitation of iOS native implantation. |
172 | 179 |
|
173 | 180 | 4. `requestHeaders` is useful together with Google API credentials restrictions by setting the `Referer` header. See [#20](https://github.com/timwangdev/react-native-geocoder-reborn/issues/20). |
174 | 181 |
|
175 | | -5. In order to avoid hitting rate limit or reducing API queries, you could cache the results in your program whenever possible. |
| 182 | +5. In order to avoid hitting rate limit or reducing API queries, you should cache the results in your program whenever possible. |
176 | 183 |
|
177 | 184 | ### `GeocodingObject` |
178 | 185 |
|
|
0 commit comments