当前位置: 首页>>代码示例>>Java>>正文


Java GeocoderResult.getAddressComponents方法代码示例

本文整理汇总了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"));
			}
		}
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:24,代码来源:TestGeocoder.java

示例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());
	}
}
 
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:31,代码来源:GeocoderUtils.java

示例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());
	}
}
 
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:36,代码来源:GeocoderUtils.java

示例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;
}
 
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:36,代码来源:GeocoderUtils.java

示例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());
				}
			}
		}
	}
}
 
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:37,代码来源:GoogleGeocoder.java


注:本文中的com.google.code.geocoder.model.GeocoderResult.getAddressComponents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。