0

そのため、GoogleマップV2を約1年間実装しましたが、問題はありません。しかし、開いたマップから気象サービスを実装した後、認証に失敗したようです。どんな助けでも大歓迎です!これは OPEN WEATHER を呼び出すクラスです。ここからの http 呼び出しが、G.Maps の認証要求の送信に干渉するのではないかと考えています。

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;
    }
}

これらはマップに関連しています

マニフェストで:

<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.............................." />

私が言った他のコードは問題なく機能したので、投稿するポイントはあまりありませんが、要求があれば実行します。ありがとう

4

1 に答える 1

0

アプリケーション全体でアクセス可能な Singleton クラスに GoogleApi クライアント キーを追加 (初期化を実行) すると、正常に動作するはずです。

私は私のためにやった このようにSingleton Class

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 +でサインインするために使用しました

于 2016-02-13T13:22:54.093 に答える