0

So I had google maps V2 implemented for about a year now, No issues with it. However after I implemented the weather service from open map , Authorization seems to fail . Any help will be greatly appreciated! This is a class that calls for OPEN WEATHER.I am wondering if the http call from here interferes with G.Maps sending request for authorization.

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

} Those are related with maps

In Manifest :

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

Any other code as i said worked fine so not much point to post, will do if requested. Thanks

kPieczonka
  • 394
  • 1
  • 14

1 Answers1

0

Add your GoogleApi client key to your Singleton class (Do a initialization) which is accessible throughout the Application and it Should work fine.

I have done for me Like this by Making a 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;
}}

Note: I have used this for Sign in with Google +

CandleCoder
  • 1,387
  • 4
  • 21
  • 45
  • Kind of lost you, whats the procedure,as I said earlier this was working fine before – kPieczonka Feb 13 '16 at 13:25
  • I have tested your solution but still getting the same error. any other ideas will be highly appropriated .thanks – kPieczonka Feb 14 '16 at 10:45
  • Refer to this http://stackoverflow.com/questions/13696620/google-maps-android-api-v2-authorization-failure – CandleCoder Feb 15 '16 at 04:09
  • Hi , yeah i have followed the above post, completed all suggestions, or more accurately checked if everything was correct, Still have the same issue. Have installed play services, set up the manifest..Nothing.. just don't know what to do next to solve this issue – kPieczonka Feb 15 '16 at 10:40
  • I have acquired a new api code from google and works fine, thanks for input – kPieczonka Feb 16 '16 at 12:33
  • Hmmm congratulations... Happy coding...Make sure...Google keeps changing their api's...Regularly visit their Official Doc...Thanks – CandleCoder Feb 16 '16 at 13:15