本文整理汇总了Java中com.google.code.geocoder.model.GeocoderResult.getAddressComponents方法的典型用法代码示例。如果您正苦于以下问题:Java GeocoderResult.getAddressComponents方法的具体用法?Java GeocoderResult.getAddressComponents怎么用?Java GeocoderResult.getAddressComponents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.code.geocoder.model.GeocoderResult
的用法示例。
在下文中一共展示了GeocoderResult.getAddressComponents方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBoundingCity
import com.google.code.geocoder.model.GeocoderResult; //导入方法依赖的package包/类
@Test
public void testBoundingCity() throws IOException {
LatLng limit_southwest = new LatLng("45.434616", "4.479726");
LatLng limit_northeast = new LatLng("45.53778", "4.889763");
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress("st martin").setRegion("fr").setLanguage("fr").getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
assertTrue(geocoderResponse.getResults().size() > 1 );
geocoderRequest = new GeocoderRequestBuilder().setAddress("st martin")
.setRegion("fr")
.setLanguage("fr")
.setBounds(new LatLngBounds(limit_southwest, limit_northeast)).getGeocoderRequest();
geocoderResponse = geocoder.geocode(geocoderRequest);
for(GeocoderResult result : geocoderResponse.getResults()) {
List<GeocoderAddressComponent> addressComponents = result.getAddressComponents();
for(GeocoderAddressComponent addressComponent : addressComponents) {
if (addressComponent.getTypes().contains(GeocoderResultType.ADMINISTRATIVE_AREA_LEVEL_1.value())) {
assertTrue(addressComponent.getLongName().equals("Rhône-Alpes"));
}
}
}
}
示例2: getGeoByPubLatLng
import com.google.code.geocoder.model.GeocoderResult; //导入方法依赖的package包/类
private static void getGeoByPubLatLng(Pub pub, final Geocoder geocoder) {
GeocoderRequest request = new GeocoderRequestBuilder()
.setAddress(pub.getLocal())
.setLocation(new LatLng(new BigDecimal(pub.getLat()), new BigDecimal(pub.getLng())))
.setLanguage("en")
.getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
if (response.getStatus().equals(GeocoderStatus.OK)) {
List<GeocoderResult> results = response.getResults();
for (GeocoderResult geoResult : results) {
List<GeocoderAddressComponent> addressComponents = geoResult.getAddressComponents();
for (GeocoderAddressComponent address : addressComponents) {
if (address.getTypes().contains("locality")) {
pub.setCity(address.getLongName());
}
if (address.getTypes().contains("administrative_area_level_1")) {
pub.setState(address.getLongName());
}
if (address.getTypes().contains("country")) {
pub.setCountry(address.getLongName());
}
}
}
} else {
log.info(response.getStatus().name());
}
}
示例3: getGeoByPubAddress
import com.google.code.geocoder.model.GeocoderResult; //导入方法依赖的package包/类
private static void getGeoByPubAddress(Pub pub, final Geocoder geocoder) {
GeocoderRequest request = new GeocoderRequestBuilder()
.setAddress(pub.getLocal())
.setLanguage("en")
.getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
if (response.getStatus().equals(GeocoderStatus.OK)) {
List<GeocoderResult> results = response.getResults();
for (GeocoderResult geoResult : results) {
BigDecimal lat = geoResult.getGeometry().getLocation().getLat();
BigDecimal lng = geoResult.getGeometry().getLocation().getLng();
pub.setLat(lat.doubleValue());
pub.setLng(lng.doubleValue());
List<GeocoderAddressComponent> addressComponents = geoResult.getAddressComponents();
for (GeocoderAddressComponent address : addressComponents) {
if (address.getTypes().contains("locality")) {
pub.setCity(address.getLongName());
}
if (address.getTypes().contains("administrative_area_level_1")) {
pub.setState(address.getLongName());
}
if (address.getTypes().contains("country")) {
pub.setCountry(address.getLongName());
}
}
}
} else {
log.info(response.getStatus().name());
}
}
示例4: getGeoByLatLng
import com.google.code.geocoder.model.GeocoderResult; //导入方法依赖的package包/类
public static Map<String, String> getGeoByLatLng(Double lat, Double lng) {
Map<String, String> map = new HashMap<String, String>();
final Geocoder geocoder = new Geocoder();
GeocoderRequest request = new GeocoderRequestBuilder()
.setLocation(new LatLng(new BigDecimal(lat), new BigDecimal(lng)))
.setLanguage("en")
.getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
if (response.getStatus().equals(GeocoderStatus.OK)) {
List<GeocoderResult> results = response.getResults();
for (GeocoderResult geoResult : results) {
List<GeocoderAddressComponent> addressComponents = geoResult.getAddressComponents();
for (GeocoderAddressComponent address : addressComponents) {
if (address.getTypes().contains("locality")) {
map.put("CITY", address.getLongName());
}
if (address.getTypes().contains("administrative_area_level_1")) {
map.put("STATE", address.getLongName());
}
if (address.getTypes().contains("country")) {
map.put("COUNTRY", address.getLongName());
}
}
}
} else {
log.info(response.getStatus().name());
}
return map;
}
示例5: main
import com.google.code.geocoder.model.GeocoderResult; //导入方法依赖的package包/类
public static void main(String[] args) {
final Geocoder geocoder = new Geocoder();
GeocoderRequest request = new GeocoderRequestBuilder()
.setAddress("The Promenade, Lahinch. Co. Clare. Ireland")
.setLanguage("en").getGeocoderRequest();
GeocodeResponse response = geocoder.geocode(request);
if (response.getStatus().equals(GeocoderStatus.OK)) {
List<GeocoderResult> results = response.getResults();
for (GeocoderResult geoResult : results) {
System.out.println(geoResult.getFormattedAddress());
BigDecimal lat = geoResult.getGeometry().getLocation().getLat();
BigDecimal lng = geoResult.getGeometry().getLocation().getLng();
System.out.println("lat: " + lat);
System.out.println("lng: " + lng);
List<GeocoderAddressComponent> addressComponents = geoResult.getAddressComponents();
for (GeocoderAddressComponent address : addressComponents) {
if (address.getTypes().contains("locality")) {
System.out.println("Cidade: " + address.getLongName());
}
if (address.getTypes().contains("administrative_area_level_1")) {
System.out.println("Estado: " + address.getLongName());
}
if (address.getTypes().contains("country")) {
System.out.println("País: " + address.getLongName());
}
}
}
}
}