react-native-maps 1.21.0-alpha.87 → 1.21.0-alpha.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,8 @@ import static com.rnmaps.maps.MapModule.SNAPSHOT_RESULT_FILE;
7
7
  import static com.rnmaps.maps.MapModule.closeQuietly;
8
8
 
9
9
  import android.graphics.Bitmap;
10
+ import android.location.Address;
11
+ import android.location.Geocoder;
10
12
  import android.net.Uri;
11
13
  import android.util.Base64;
12
14
  import android.util.DisplayMetrics;
@@ -33,6 +35,8 @@ import org.json.JSONObject;
33
35
  import java.io.ByteArrayOutputStream;
34
36
  import java.io.File;
35
37
  import java.io.FileOutputStream;
38
+ import java.io.IOException;
39
+ import java.util.List;
36
40
 
37
41
  public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
38
42
  public NativeAirMapsModule(ReactApplicationContext reactContext) {
@@ -188,6 +192,41 @@ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
188
192
 
189
193
  @Override
190
194
  public void getAddressFromCoordinates(double tag, ReadableMap coordinate, Promise promise) {
195
+ final ReactApplicationContext context = getReactApplicationContext();
196
+
197
+ if (coordinate == null ||
198
+ !coordinate.hasKey("latitude") ||
199
+ !coordinate.hasKey("longitude")) {
200
+ promise.reject("Invalid coordinate format");
201
+ return;
202
+ }
203
+ Geocoder geocoder = new Geocoder(context);
204
+ try {
205
+ List<Address> list =
206
+ geocoder.getFromLocation(coordinate.getDouble("latitude"), coordinate.getDouble("longitude"), 1);
207
+ if (list.isEmpty()) {
208
+ promise.reject("Can not get address location");
209
+ return;
210
+ }
211
+ Address address = list.get(0);
212
+
213
+ WritableMap addressJson = new WritableNativeMap();
214
+ addressJson.putString("name", address.getFeatureName());
215
+ addressJson.putString("locality", address.getLocality());
216
+ addressJson.putString("thoroughfare", address.getThoroughfare());
217
+ addressJson.putString("subThoroughfare", address.getSubThoroughfare());
218
+ addressJson.putString("subLocality", address.getSubLocality());
219
+ addressJson.putString("administrativeArea", address.getAdminArea());
220
+ addressJson.putString("subAdministrativeArea", address.getSubAdminArea());
221
+ addressJson.putString("postalCode", address.getPostalCode());
222
+ addressJson.putString("countryCode", address.getCountryCode());
223
+ addressJson.putString("country", address.getCountryName());
224
+
225
+ promise.resolve(addressJson);
226
+ } catch (IOException e) {
227
+ promise.reject("Can not get address location");
228
+ }
229
+
191
230
 
192
231
  }
193
232
 
package/lib/MapView.js CHANGED
@@ -218,13 +218,8 @@ class MapView extends React.Component {
218
218
  * @return Promise with return type Address
219
219
  */
220
220
  addressForCoordinate(coordinate) {
221
- if (react_native_1.Platform.OS === 'android') {
222
- return react_native_1.NativeModules.AirMapModule.getAddressFromCoordinates(this._getHandle(), coordinate);
223
- }
224
- else if (react_native_1.Platform.OS === 'ios') {
225
- if (this.fabricMap.current) {
226
- return this.fabricMap.current.getAddressFromCoordinates(coordinate);
227
- }
221
+ if (this.fabricMap.current) {
222
+ return this.fabricMap.current.getAddressFromCoordinates(coordinate);
228
223
  }
229
224
  return Promise.reject('getAddress not supported on this platform');
230
225
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "main": "lib/index.js",
6
6
  "author": "Leland Richardson <leland.m.richardson@gmail.com>",
7
7
  "homepage": "https://github.com/react-native-maps/react-native-maps#readme",
8
- "version": "1.21.0-alpha.87",
8
+ "version": "1.21.0-alpha.88",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",