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

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,9 @@ 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.graphics.Point;
11
+ import android.location.Address;
12
+ import android.location.Geocoder;
10
13
  import android.net.Uri;
11
14
  import android.util.Base64;
12
15
  import android.util.DisplayMetrics;
@@ -24,6 +27,7 @@ import com.facebook.react.bridge.WritableNativeMap;
24
27
  import com.facebook.react.uimanager.UIManagerHelper;
25
28
  import com.google.android.gms.maps.GoogleMap;
26
29
  import com.google.android.gms.maps.model.CameraPosition;
30
+ import com.google.android.gms.maps.model.LatLng;
27
31
  import com.rnmaps.maps.MapUIBlock;
28
32
  import com.rnmaps.maps.MapView;
29
33
 
@@ -33,6 +37,8 @@ import org.json.JSONObject;
33
37
  import java.io.ByteArrayOutputStream;
34
38
  import java.io.File;
35
39
  import java.io.FileOutputStream;
40
+ import java.io.IOException;
41
+ import java.util.List;
36
42
 
37
43
  public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
38
44
  public NativeAirMapsModule(ReactApplicationContext reactContext) {
@@ -188,16 +194,91 @@ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
188
194
 
189
195
  @Override
190
196
  public void getAddressFromCoordinates(double tag, ReadableMap coordinate, Promise promise) {
197
+ final ReactApplicationContext context = getReactApplicationContext();
198
+
199
+ if (coordinate == null ||
200
+ !coordinate.hasKey("latitude") ||
201
+ !coordinate.hasKey("longitude")) {
202
+ promise.reject("Invalid coordinate format");
203
+ return;
204
+ }
205
+ Geocoder geocoder = new Geocoder(context);
206
+ try {
207
+ List<Address> list =
208
+ geocoder.getFromLocation(coordinate.getDouble("latitude"), coordinate.getDouble("longitude"), 1);
209
+ if (list.isEmpty()) {
210
+ promise.reject("Can not get address location");
211
+ return;
212
+ }
213
+ Address address = list.get(0);
214
+
215
+ WritableMap addressJson = new WritableNativeMap();
216
+ addressJson.putString("name", address.getFeatureName());
217
+ addressJson.putString("locality", address.getLocality());
218
+ addressJson.putString("thoroughfare", address.getThoroughfare());
219
+ addressJson.putString("subThoroughfare", address.getSubThoroughfare());
220
+ addressJson.putString("subLocality", address.getSubLocality());
221
+ addressJson.putString("administrativeArea", address.getAdminArea());
222
+ addressJson.putString("subAdministrativeArea", address.getSubAdminArea());
223
+ addressJson.putString("postalCode", address.getPostalCode());
224
+ addressJson.putString("countryCode", address.getCountryCode());
225
+ addressJson.putString("country", address.getCountryName());
226
+
227
+ promise.resolve(addressJson);
228
+ } catch (IOException e) {
229
+ promise.reject("Can not get address location");
230
+ }
231
+
191
232
 
192
233
  }
193
234
 
194
235
  @Override
195
236
  public void getPointForCoordinate(double tag, ReadableMap coordinate, Promise promise) {
237
+ final ReactApplicationContext context = getReactApplicationContext();
238
+ final double density = (double) context.getResources().getDisplayMetrics().density;
239
+
240
+ final LatLng coord = new LatLng(
241
+ coordinate.hasKey("latitude") ? coordinate.getDouble("latitude") : 0.0,
242
+ coordinate.hasKey("longitude") ? coordinate.getDouble("longitude") : 0.0
243
+ );
244
+
245
+ MapUIBlock uiBlock = new MapUIBlock((int) tag, promise, context, view -> {
246
+ Point pt = view.map.getProjection().toScreenLocation(coord);
196
247
 
248
+ WritableMap ptJson = new WritableNativeMap();
249
+ ptJson.putDouble("x", (double) pt.x / density);
250
+ ptJson.putDouble("y", (double) pt.y / density);
251
+
252
+ promise.resolve(ptJson);
253
+
254
+ return null;
255
+ });
256
+
257
+ uiBlock.addToUIManager();
197
258
  }
198
259
 
199
260
  @Override
200
261
  public void getCoordinateForPoint(double tag, ReadableMap point, Promise promise) {
262
+ final ReactApplicationContext context = getReactApplicationContext();
263
+ final double density = (double) context.getResources().getDisplayMetrics().density;
264
+
265
+ final Point pt = new Point(
266
+ point.hasKey("x") ? (int) (point.getDouble("x") * density) : 0,
267
+ point.hasKey("y") ? (int) (point.getDouble("y") * density) : 0
268
+ );
269
+
270
+ MapUIBlock uiBlock = new MapUIBlock((int)tag, promise, context, view -> {
271
+ LatLng coord = view.map.getProjection().fromScreenLocation(pt);
272
+
273
+ WritableMap coordJson = new WritableNativeMap();
274
+ coordJson.putDouble("latitude", coord.latitude);
275
+ coordJson.putDouble("longitude", coord.longitude);
276
+
277
+ promise.resolve(coordJson);
278
+
279
+ return null;
280
+ });
201
281
 
282
+ uiBlock.addToUIManager();
202
283
  }
203
284
  }
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
  }
@@ -238,13 +233,8 @@ class MapView extends React.Component {
238
233
  * @return Promise Promise with the point ({ x: Number, y: Number })
239
234
  */
240
235
  pointForCoordinate(coordinate) {
241
- if (react_native_1.Platform.OS === 'android') {
242
- return react_native_1.NativeModules.AirMapModule.pointForCoordinate(this._getHandle(), coordinate);
243
- }
244
- else if (react_native_1.Platform.OS === 'ios') {
245
- if (this.fabricMap.current) {
246
- return this.fabricMap.current.getPointForCoordinate(coordinate);
247
- }
236
+ if (this.fabricMap.current) {
237
+ return this.fabricMap.current.getPointForCoordinate(coordinate);
248
238
  }
249
239
  return Promise.reject('pointForCoordinate not supported on this platform');
250
240
  }
@@ -258,13 +248,8 @@ class MapView extends React.Component {
258
248
  * @return Promise Promise with the coordinate ({ latitude: Number, longitude: Number })
259
249
  */
260
250
  coordinateForPoint(point) {
261
- if (react_native_1.Platform.OS === 'android') {
262
- return react_native_1.NativeModules.AirMapModule.coordinateForPoint(this._getHandle(), point);
263
- }
264
- else if (react_native_1.Platform.OS === 'ios') {
265
- if (this.fabricMap.current) {
266
- return this.fabricMap.current.getCoordinateForPoint(point);
267
- }
251
+ if (this.fabricMap.current) {
252
+ return this.fabricMap.current.getCoordinateForPoint(point);
268
253
  }
269
254
  return Promise.reject('coordinateForPoint not supported on this platform');
270
255
  }
@@ -54,7 +54,7 @@ const createFabricMap = (ViewComponent, Commands) => {
54
54
  return NativeAirMapsModule_1.default.getPointForCoordinate((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
55
55
  }
56
56
  else {
57
- throw new Error('getPointForCoordinate is only supported on iOS with Fabric.');
57
+ throw new Error('getPointForCoordinate is not supported on this platform.');
58
58
  }
59
59
  },
60
60
  async getAddressFromCoordinates(coordinate) {
@@ -62,7 +62,7 @@ const createFabricMap = (ViewComponent, Commands) => {
62
62
  return NativeAirMapsModule_1.default.getAddressFromCoordinates((0, react_native_1.findNodeHandle)(fabricRef.current) ?? -1, coordinate);
63
63
  }
64
64
  else {
65
- throw new Error('getAddressFromCoordinates is only supported on iOS with Fabric.');
65
+ throw new Error('getAddressFromCoordinates is not supported on this platform');
66
66
  }
67
67
  },
68
68
  async takeSnapshot(config) {
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.89",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",