Elgert
Elgert

Reputation: 470

Map view appears white

Until recently map view was working ok but now appears white even though i get the address from the location out of it as you can see in the picture

enter image description here

What can it be the problem im out of guesses

the code is this

@Override public Bitmap doInBackground(Void... params) {

    String url = String.format(
        "http://maps.google.com/maps/api/staticmap?center=%f,%f&zoom=16&size=%dx300&sensor=false&key=%s",
        lat,
        lon,
        imageWidth,
        context.getResources().getString(R.string.mapApiKey2)
    );

    Log.d("MAP REQUEST ", "" + url);
    Bitmap bmp = null;
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);

    InputStream in;
    try {
        in = httpclient.execute(request).getEntity().getContent();
        bmp = BitmapFactory.decodeStream(in);
        in.close();
    } catch (IllegalStateException e) {
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }
    return bmp;
}

Also my MapView works OK, so the problem is with this static map.

If i take the url generated in this code and paste it on the browser i get

The Google Maps API server rejected your request. This API project is not authorized to use this API. Please ensure that this API is activated in the APIs Console: Learn more: https://code.google.com/apis/console

but i dont understand because I have already activated it there

Upvotes: 0

Views: 682

Answers (3)

Elgert
Elgert

Reputation: 470

Well It was just that I didn't activate the correct API, it seems like google now has different API's for different purposes.

I had activated only Google Maps Android API v2 and everything was alright but now i had to activate also Static Maps API

Upvotes: 1

Simas
Simas

Reputation: 44158

Common mistake #1. Please do not leave empty catch statements! This can, and eventually will lead to hidden errors.

At least print the stackstrace in each of them:

e.printStackTrace():

Upvotes: 0

hrishitiwari
hrishitiwari

Reputation: 644

Here are a few possibilities:

  1. You changed the keystore to make the application (debug vs production), you need a different Google Maps API key for each keystore.

  2. Are you able to access internet? In my case, I was using a VPN to access my app's webservice endpoints, but the VPN blocked internet access, causing my maps to become like this.

Hope this helps.

Upvotes: 0

Related Questions