首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌地图正在工作,在实施OpenMap天气service.Getting授权失败后停止

谷歌地图正在工作,在实施OpenMap天气service.Getting授权失败后停止
EN

Stack Overflow用户
提问于 2016-02-13 21:12:20
回答 1查看 69关注 0票数 0

所以我让谷歌地图V2实现了大约一年,没有任何问题。然而,在我从开放地图实现天气服务后,授权似乎失败了。任何帮助都将不胜感激!这是一个调用OPEN WEATHER.I的类。我想知道从这里发出的http调用是否会干扰G.Maps发送授权请求。

代码语言:javascript
复制
public class RemoteFetch {

private static final String OPEN_WEATHER_MAP_API =
        "http://api.openweathermap.org/data/2.5/weather?q=%s&units=metric";

public static JSONObject getJSON(Context context, String city){
    try {
        URL url = new URL(String.format(OPEN_WEATHER_MAP_API, city));
        HttpURLConnection connection =
                (HttpURLConnection)url.openConnection();

        connection.addRequestProperty("x-api-key",
                context.getString(R.string.open_weather_maps_app_id));

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(connection.getInputStream()));

        StringBuffer json = new StringBuffer(1024);
        String tmp="";
        while((tmp=reader.readLine())!=null)
            json.append(tmp).append("\n");
        reader.close();

        JSONObject data = new JSONObject(json.toString());

        // This value will be 404 if the request was not
        // successful
        if(data.getInt("cod") != 200){
            return null;
        }

        return data;
    }catch(Exception e){
        return null;
    }
}

}这些与地图相关

在清单中:

代码语言:javascript
复制
<permission
        android:name="donate.cinek.wit.ie.ridetogether.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

  <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<uses-permission android:name="donate.cinek.wit.ie.ridetogether.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
  <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIza.............................." />

任何其他代码,如我所说的工作很好,所以没有太多的点后,将做,如果要求。谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-02-13 21:22:54

将您的GoogleApi客户端密钥添加到可在整个应用程序中访问的单例类中(执行初始化),它应该工作得很好。

我为自己做了这样一个Singleton Class

代码语言:javascript
复制
public class Model {

private static Model singleton = new Model( );
private GoogleApiClient _googleClient;


public void setGoogleClient(GoogleApiClient client){

    this._googleClient = client;


}

public GoogleApiClient getGoogleClient(){

    return this._googleClient;
}}

Google 备注:我用它来登录

+

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35380316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档