0
我正在开发的项目作为一个Web应用程序进行跟踪。现在我需要从给定的经度和纬度访问街道地址,州和国家。 所以我需要的代码。如何从经度和纬度访问地址位置?访问地址,从经度和谷歌状态谷歌API
我必须使用的Google API: https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters。
我需要谷歌反向地理编码还与JSON?
我正在开发的项目作为一个Web应用程序进行跟踪。现在我需要从给定的经度和纬度访问街道地址,州和国家。 所以我需要的代码。如何从经度和纬度访问地址位置?访问地址,从经度和谷歌状态谷歌API
我必须使用的Google API: https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters。
我需要谷歌反向地理编码还与JSON?
我不喜欢这样,(代码是自我解释):
[...]
GeoApiContext context = new GeoApiContext().setApiKey("your-key");
GeocodingApiRequest request = GeocodingApi.newRequest(context);
request.latlng(new LatLng(lat, lon));
request.resultType(AddressType.STREET_ADDRESS);
GeocodingResult[] results = request.await(); // try catch?
for(GeocodingResult r : results){
for (AddressComponent ac : r.addressComponents) {
System.out.println(ac);
}
}
for(GeocodingResult r : results){
for (AddressComponent ac : r.addressComponents) {
for (AddressComponentType acType : ac.types) {
if (acType == AddressComponentType.LOCALITY) {
System.out.println(ac.longName);
} else if (acType == AddressComponentType.STREET_ADDRESS) {
System.out.println(ac.longName);
} else if (acType == AddressComponentType.COUNTRY) {
System.out.println(ac.longName);
}
}
}
}
不要忘了,包括Maven的依赖性:
<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>0.1.15</version>
</dependency>
我我正在获取错误找不到符号:AddressComponent, AddressType – vignesh
You需要'google-maps-services.jar'。请参阅我的答案或此链接中的maven坐标:https://mvnrepository.com/artifact/com.google.maps/google-maps-services/0.1.15 – dit