MapboxGeocoding 返回无效的纬度和经度 (Android)
MapboxGeocoding returning invalid lat and long (Android)
我主要是想从输入的地址中获取纬度和经度,但是 MapboxGeocoding 方法 returns 无效的坐标不在 -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();
returns 的坐标:
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.onResponse(SearchLocationActivity.java:222)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.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)
为什么会这样,是因为我使用的是 public mapbox 密钥吗?
我相信
.target(new LatLng(firstResultPoint.longitude(), firstResultPoint.latitude()))
应该是
.target(new LatLng(firstResultPoint.latitude(), firstResultPoint.longitude()))
顾名思义 LatLng。
我主要是想从输入的地址中获取纬度和经度,但是 MapboxGeocoding 方法 returns 无效的坐标不在 -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();
returns 的坐标:
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.onResponse(SearchLocationActivity.java:222)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.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)
为什么会这样,是因为我使用的是 public mapbox 密钥吗?
我相信
.target(new LatLng(firstResultPoint.longitude(), firstResultPoint.latitude()))
应该是
.target(new LatLng(firstResultPoint.latitude(), firstResultPoint.longitude()))
顾名思义 LatLng。