Google的地理编码API示例无效

时间:2015-06-10 10:57:23

标签: java eclipse google-maps

我想测试googles hompage (the code)的GeocodingAPI示例。

我在eclipse中使用Java,我已经将库“google-maps-services 0.1.7”添加到我的项目中。这是我的代码:

package test;

import com.google.maps.*;
import com.google.maps.model.GeocodingResult;

public class Distance {

public static void main(String[] args) throws Exception {

    GeoApiContext context = new GeoApiContext().setApiKey("AIza...");
    GeocodingResult[] results =  GeocodingApi.geocode(context,
        "1600 Amphitheatre Parkway Mountain View, CA 94043").await();
    System.out.println(results[0].formattedAddress);    
    }
}

当我想运行代码时,控制台中会显示以下问题:

Exception in thread "main" java.lang.NoClassDefFoundError:     com/squareup/okhttp/OkHttpClient
at com.google.maps.GeoApiContext.<init>(GeoApiContext.java:50)
at test.Distance.main(Distance.java:10)
Caused by: java.lang.ClassNotFoundException: com.squareup.okhttp.OkHttpClient
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

我将API更改为我的个人API。这段代码有什么问题?导入说明中是否有错误?

0 个答案:

没有答案