使用Google API访问地址,经度和纬度状态 [英] Accessing adress,states from longitude amd lattitude with google API

查看:85
本文介绍了使用Google API访问地址,经度和纬度状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发作为Web应用程序进行跟踪的项目.现在,我需要从给定的经度和纬度访问街道地址,州和国家/地区. 所以我需要代码.如何从经纬度访问地址位置?

I am developing project for tracking as a web application. Now I need to access a street address, states and country from given lattitude and longitude. So I need the code. How to access address location from latitude and longitude?

我必须使用的Google API: https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters .

The Google API which I have to use: https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters.

我还需要带有JSON的Google反向地理编码吗?

I need Google reverse Geocode also with JSON?

推荐答案

我这样做,(代码不解自明):

I do it like this, (code is self-explaining):

[...]
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);
    }
}

还要检查别忘了包含maven依赖项:

Dont forget to include maven dependency:

<dependency>
    <groupId>com.google.maps</groupId>
    <artifactId>google-maps-services</artifactId>
    <version>0.1.15</version>
</dependency>

这篇关于使用Google API访问地址,经度和纬度状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆