本文整理汇总了Java中com.google.maps.model.AddressComponentType类的典型用法代码示例。如果您正苦于以下问题:Java AddressComponentType类的具体用法?Java AddressComponentType怎么用?Java AddressComponentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AddressComponentType类属于com.google.maps.model包,在下文中一共展示了AddressComponentType类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: Address
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
@SneakyThrows
public Address(String address) {
this.address = address;
if (address != null && geoApiContext != null) {
GeocodingResult[] results = GeocodingApi.geocode(geoApiContext, address).await();
if (results.length > 0) {
GeocodingResult result = results[0];
for (AddressComponent component : result.addressComponents) {
List<AddressComponentType> types = Arrays.asList(component.types);
if (types.contains(AddressComponentType.COUNTRY)) {
this.country = component.longName;
}
if (types.contains(AddressComponentType.LOCALITY)) {
this.city = component.longName;
}
if (types.contains(AddressComponentType.POSTAL_CODE)) {
this.postalCode = component.longName;
}
}
this.latitude = result.geometry.location.lat;
this.longitude = result.geometry.location.lng;
}
}
}
开发者ID:eventsourcing,项目名称:es4j,代码行数:25,代码来源:Address.java
示例2: testSimpleReverseGeocode
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
/**
* Simple reverse geocoding. <a
* href="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452">Reverse
* geocode (40.714224,-73.961452)</a>.
*/
@Test
public void testSimpleReverseGeocode() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext(simpleReverseGeocodeResponse)) {
LatLng latlng = new LatLng(40.714224, -73.961452);
GeocodingResult[] results = GeocodingApi.newRequest(sc.context).latlng(latlng).await();
assertNotNull(results);
assertEquals("277 Bedford Ave, Brooklyn, NY 11211, USA", results[0].formattedAddress);
assertEquals("277", results[0].addressComponents[0].longName);
assertEquals("277", results[0].addressComponents[0].shortName);
assertEquals(AddressComponentType.STREET_NUMBER, results[0].addressComponents[0].types[0]);
assertEquals(AddressType.STREET_ADDRESS, results[0].types[0]);
sc.assertParamValue(latlng.toUrlValue(), "latlng");
}
}
开发者ID:googlemaps,项目名称:google-maps-services-java,代码行数:22,代码来源:GeocodingApiTest.java
示例3: testReverseGeocodeWithKitaWard
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
/** Testing Kita Ward reverse geocode. */
@Test
public void testReverseGeocodeWithKitaWard() throws Exception {
try (LocalTestServerContext sc =
new LocalTestServerContext(reverseGeocodeWithKitaWardResponse)) {
LatLng location = new LatLng(35.03937, 135.729243);
GeocodingResult[] results = GeocodingApi.newRequest(sc.context).latlng(location).await();
assertNotNull(results);
assertEquals(
"Japan, 〒603-8361 Kyōto-fu, Kyōto-shi, Kita-ku, Kinkakujichō, 1 北山鹿苑寺金閣寺",
results[0].formattedAddress);
assertEquals("Kita Ward", results[3].addressComponents[0].shortName);
assertEquals("Kita Ward", results[3].addressComponents[0].longName);
assertEquals(AddressComponentType.LOCALITY, results[3].addressComponents[0].types[0]);
assertEquals(AddressComponentType.POLITICAL, results[3].addressComponents[0].types[1]);
assertEquals(AddressComponentType.WARD, results[3].addressComponents[0].types[2]);
sc.assertParamValue(location.toUrlValue(), "latlng");
}
}
开发者ID:googlemaps,项目名称:google-maps-services-java,代码行数:22,代码来源:GeocodingApiTest.java
示例4: testGetLocationInfo
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
@Test
public void testGetLocationInfo() throws Exception {
String zipCode = "30332";
Program program = new Program();
program.setCity("Atlanta");
program.setState("GA");
program.setStreetAddress("123 Peachtree St.");
program.setZipCode(zipCode);
String expectedFormattedAddress = "123 Peachtree St. Atlanta, GA 30332";
LocationInfo expected = new LocationInfo();
expected.setLngLat("-1.23456789,9.87654321");
expected.setZipCode(zipCode);
AddressComponent addressComponent = new AddressComponent();
addressComponent.longName = zipCode;
addressComponent.types = new AddressComponentType[] {AddressComponentType.POSTAL_CODE};
LatLng latLng = new LatLng(9.87654321, -1.23456789);
Geometry geometry = new Geometry();
geometry.location = latLng;
GeocodingResult geocodingResult = new GeocodingResult();
geocodingResult.geometry = geometry;
geocodingResult.addressComponents = new AddressComponent[] {addressComponent};
GeocodingResult[] expectedGeocodingResult = new GeocodingResult[] {geocodingResult};
/* Train the mocks. */
when(googleGeocodeClient.geocode(expectedFormattedAddress)).thenReturn(expectedGeocodingResult);
/* Make the call. */
LocationInfo actual = toTest.getLocationInfo(program);
/* Verify the results. */
assertEquals(expected, actual);
}
开发者ID:healthbam,项目名称:healthbam,代码行数:37,代码来源:GoogleGeocodeServiceTest.java
示例5: testGetLocationInfoFillZipAlso
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
@Test
public void testGetLocationInfoFillZipAlso() throws Exception {
String zipCode = "30332";
Program program = new Program();
program.setCity("Atlanta");
program.setState("GA");
program.setStreetAddress("123 Peachtree St.");
String expectedFormattedAddress = "123 Peachtree St. Atlanta, GA ";
LocationInfo expected = new LocationInfo();
expected.setLngLat("-1.23456789,9.87654321");
expected.setZipCode(zipCode);
AddressComponent addressComponent = new AddressComponent();
addressComponent.longName = zipCode;
addressComponent.types = new AddressComponentType[] {AddressComponentType.POSTAL_CODE};
LatLng latLng = new LatLng(9.87654321, -1.23456789);
Geometry geometry = new Geometry();
geometry.location = latLng;
GeocodingResult geocodingResult = new GeocodingResult();
geocodingResult.geometry = geometry;
geocodingResult.addressComponents = new AddressComponent[] {addressComponent};
GeocodingResult[] expectedGeocodingResult = new GeocodingResult[] {geocodingResult};
/* Train the mocks. */
when(googleGeocodeClient.geocode(expectedFormattedAddress)).thenReturn(expectedGeocodingResult);
/* Make the call. */
LocationInfo actual = toTest.getLocationInfo(program);
/* Verify the results. */
assertEquals(expected, actual);
}
开发者ID:healthbam,项目名称:healthbam,代码行数:36,代码来源:GoogleGeocodeServiceTest.java
示例6: checkComponents
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
/**
* Checks if the address in a geocoding result is acceptable.
*
* The address should have at least a PREMISE, ROUTE, STREET_NUMBER or SUBLOCALITY_LEVEL_4 component (these criteria are completely ad hoc)
*
* @param result A <code>GeocodingResult</code> returned by the Google Maps API.
* @return <code>true</code> if the address is acceptable, <code>false</code> otherwise.
*/
public static boolean checkComponents(GeocodingResult result) {
for (AddressComponent component : result.addressComponents) {
for (Object componentType : component.types) {
if (componentType == AddressComponentType.PREMISE) return true;
if (componentType == AddressComponentType.ROUTE) return true;
if (componentType == AddressComponentType.STREET_NUMBER) return true;
if (componentType == AddressComponentType.SUBLOCALITY_LEVEL_4) return true;
}
}
return false;
}
开发者ID:FranckCo,项目名称:Stamina,代码行数:21,代码来源:NSISModelMaker.java
示例7: ehCidade
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
public static boolean ehCidade(AddressComponentType[] types) {
return contemTipo(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_2, types)
&& contemTipo(AddressComponentType.POLITICAL, types);
}
开发者ID:ortolanph,项目名称:hojeehdiaderua,代码行数:5,代码来源:CalendarioService.java
示例8: ehEstado
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
public static boolean ehEstado(AddressComponentType[] types) {
return contemTipo(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_1, types)
&& contemTipo(AddressComponentType.POLITICAL, types);
}
开发者ID:ortolanph,项目名称:hojeehdiaderua,代码行数:5,代码来源:CalendarioService.java
示例9: contemTipo
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
private static boolean contemTipo(AddressComponentType tipo, AddressComponentType[] tipos) {
List<AddressComponentType> types = new ArrayList<>(Arrays.asList(tipos));
return types.contains(tipo);
}
开发者ID:ortolanph,项目名称:hojeehdiaderua,代码行数:6,代码来源:CalendarioService.java
示例10: ehRota
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
private boolean ehRota(AddressComponentType[] types) {
return contemTipo(AddressComponentType.ROUTE, types);
}
开发者ID:ortolanph,项目名称:hojeehdiaderua,代码行数:4,代码来源:CalendarioService.java
示例11: getLocationInfo
import com.google.maps.model.AddressComponentType; //导入依赖的package包/类
@Timed
@Override
public LocationInfo getLocationInfo(
@Nonnull Program program
) {
LOGGER.debug("getLngLat called: program={}", program);
requireNonNull(program, "program cannot be null");
String address = formatAddress(program);
GeocodingResult[] results;
try {
results = googleGeocodeClient.geocode(address);
} catch (Exception e) {
throw new RuntimeException("Failed to geocode address: " + address, e);
}
LocationInfo info = new LocationInfo();
for (AddressComponent component : results[0].addressComponents) {
for (AddressComponentType type : component.types) {
if (AddressComponentType.POSTAL_CODE.equals(type)) {
info.setZipCode(component.longName);
}
}
}
/* I have to do this instead of using toUrlValue() because the map expects "lng,lat" instead of "lat,lng". */
info.setLngLat(
String.format(
Locale.ENGLISH,
"%.8f,%.8f",
results[0].geometry.location.lng,
results[0].geometry.location.lat
)
);
return info;
}
开发者ID:healthbam,项目名称:healthbam,代码行数:43,代码来源:GoogleGeocodeService.java
注:本文中的com.google.maps.model.AddressComponentType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论