MapboxGeocoding返回无效的lat和long(Android)



我基本上是想从输入的地址中获取Lat和Long,但MapboxGeocoding方法返回的坐标无效,不在-90到90之间。

MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder()
.accessToken(getString(R.string.access_token))
.query("50 Beale St, San Francisco, CA")
.build();
Log.d(TAG, "THe mapbox geocode: " + mapboxGeocoding.toString());
mapboxGeocoding.enqueueCall(new Callback<GeocodingResponse>() {
@Override
public void onResponse(Call<GeocodingResponse> call, Response<GeocodingResponse> response) {
if (response.body() != null) {

List<CarmenFeature> results = response.body().features();
Log.d(TAG, "carmen response : " + results.toString());
if (results.size() > 0) {
// Log the first results Point.
Point firstResultPoint = results.get(0).center();
Log.d(TAG, "Lat : " + firstResultPoint.longitude());
Log.d(TAG, "long : " + firstResultPoint.latitude());
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(firstResultPoint.longitude(), firstResultPoint.latitude()))
.zoom(17)
.build()), 4000);
Log.d(TAG, "onResponse: " + firstResultPoint.toString());
} else {
// No result for your request were found.
Log.d(TAG, "onResponse: No result found");
}
} else {
Log.d(TAG, "onResponse: Nothing found");
}
}

此处的此部分:

MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder()
.accessToken(getString(R.string.access_token))
.query("50 Beale St, San Francisco, CA")
.build();

返回坐标:

Lat : -122.396457
long : 37.791239

这是完全错误的,我的日志:

12-04 10:52:21.531 11351-11351/io.apptizer.business.clover E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.apptizer.business.clover, PID: 11351
java.lang.IllegalArgumentException: latitude must be between -90 and 90
at com.mapbox.mapboxsdk.geometry.LatLng.setLatitude(LatLng.java:132)
at com.mapbox.mapboxsdk.geometry.LatLng.<init>(LatLng.java:67)
at io.apptizer.pos.activity.SearchLocationActivity$2.onResponse(SearchLocationActivity.java:222)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

为什么会发生这种情况,是因为我使用了公共地图框密钥吗?

我相信

.target(new LatLng(firstResultPoint.longitude(), firstResultPoint.latitude()))

应该是

.target(new LatLng(firstResultPoint.latitude(), firstResultPoint.longitude()))

正如LatLng这个名字所暗示的那样。

最新更新