Created
March 23, 2018 02:29
-
-
Save rjuevesano/9493914aa6e7c2ac3e6ade49cde8c7fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package <PACKAGE_NAME> | |
import android.util.Log; | |
import com.baidu.mapapi.model.LatLng; | |
import com.baidu.mapapi.search.core.SearchResult; | |
import com.baidu.mapapi.search.geocode.GeoCodeResult; | |
import com.baidu.mapapi.search.geocode.GeoCoder; | |
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener; | |
import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption; | |
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult; | |
import com.facebook.react.bridge.Arguments; | |
import com.facebook.react.bridge.Promise; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.bridge.ReactContextBaseJavaModule; | |
import com.facebook.react.bridge.ReactMethod; | |
import com.facebook.react.bridge.ReadableArray; | |
import com.facebook.react.bridge.WritableMap; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
public class BaiduMapUtilModule extends ReactContextBaseJavaModule { | |
public static final String RCT_CLASS = "RCTBaiduMapUtil"; | |
public BaiduMapUtilModule(ReactApplicationContext reactContextBaseJavaModule) { | |
super(reactContextBaseJavaModule); | |
} | |
@Override | |
public String getName() { | |
return RCT_CLASS; | |
} | |
@ReactMethod | |
public void reverseGeoCode(ReadableArray array, final Promise promise){ | |
Log.e(RCT_CLASS, "center:" + array); | |
if (array != null && array.size()>1) { | |
LatLng point = new LatLng(array.getDouble(0), array.getDouble(1)); | |
// Create a geocoding retrieval instance | |
final GeoCoder geoCoder = GeoCoder.newInstance(); | |
OnGetGeoCoderResultListener listener = new OnGetGeoCoderResultListener() { | |
// Anti geocoding query result callback function | |
@Override | |
public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) { | |
//Promise promise = promiseList.get(0); | |
if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { | |
// No result detected | |
promise.reject("message", "No address detected"); | |
} else { | |
Log.e(RCT_CLASS, "onGetReverseGeoCodeResult:" + result.getAddress()); | |
promise.resolve(result.getAddress()); | |
} | |
geoCoder.destroy(); | |
} | |
@Override | |
public void onGetGeoCodeResult(GeoCodeResult result) { | |
geoCoder.destroy(); | |
} | |
}; | |
geoCoder.setOnGetGeoCodeResultListener(listener); | |
geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(point)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment