如何正确使用GeolocationApiRequest

时间:2019-07-04 16:01:47

标签: java google-maps google-maps-services-java

我正试图从这种惊人的依赖关系中实现GeolocationApiRequest

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

我从这里得到了依赖:How do I draw a route, along an existing road, between two points?

实施了GeolocationApiRequest,最后我设法使它像这样工作:

     GeoApiContext context = new GeoApiContext.Builder()
                .apiKey("MY KEY")
                .build();
        GeolocationPayloadBuilder payloadBuilder = new GeolocationPayload.GeolocationPayloadBuilder();
        GeolocationPayload payload = payloadBuilder.createGeolocationPayload();
        GeolocationApiRequest req = (GeolocationApiRequest) GeolocationApi.geolocate(context, payload);
        try {
            GeolocationResult res = req.await();
            System.out.println(res.location);
            System.out.println(res.accuracy);
        }catch (Exception e) {
            System.out.println(e);
        }

但是有时我得到的结果是非常不准确的(有时超过1000米),如果有的话,我可能需要做更多的事情才能使其更加准确 e已经为此工作,感谢您的帮助。

我测试过https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation会给我与服务相同的结果,所以我做错什么也不是问题,但是无论如何,如果有人知道一个窍门或一些要解决的问题,我将悬而未决。使其更准确,他/她将获得最佳答案

0 个答案:

没有答案