有没有人有使用Mapbox获取地址的纬度和经度的示例?
查看Mapbox Android SDK指南,按照以下步骤操作:
不要在主UI线程上执行任何示例代码。
示例1:
请注意,position
参数是可选的,但会加快获取结果的速度。
// position used for proximity
Position position = Position.fromCoordinates(-73.98572, 40.74843);
MapboxGeocoding client = new MapboxGeocoding.Builder()
.setAccessToken("<your access token here>")
.setLocation("Empire State Building")
.setProximity(position)
.build();
Response<GeocodingResponse> response = client.execute();
例子2:
MapboxGeocoding client = new MapboxGeocoding.Builder()
.setAccessToken("<your access token here>")
.setLocation("Empire State Building")
.build();
Response<GeocodingResponse> response = client.execute();
Mapbox.GeocodingBuilder
,获取一个 Response
,并从 Response
中访问你想要的字段。private void simpleSample() {
MapboxGeocoder client = new MapboxGeocoder.Builder()
.setAccessToken(MAPBOX_ACCESS_TOKEN)
.setLocation("The White House")
.build();
client.enqueue(new Callback<GeocoderResponse>() {
@Override
public void onResponse(Response<GeocoderResponse> response, Retrofit retrofit) {
// Features, basically, is a list of search results
// get the first one
// get latitude and longitude
String latitude = response.body().getFeatures().get(0).getLatitude();
String longitude = response.body().getFeatures().get(0).getLongitude();
}
@Override
public void onFailure(Throwable t) {
// log t.getMessage()
}
});
}
build.gradle
中包含 Mapbox Android Services SDK,并按照此示例进行操作。 - cammace