Google Map API v2 grey tiles, everything worked fine (code inside) - android

Everything was working fine, the only problem I had is when I change the city to some place south in my country and I get the common "app stopped working problem" but that's fine, I also think what messed this thing up is when I tried to export the application and filled the keystore fields etc.
I searched everywhere on Google and didn't find anything useful, all the solutions I've tried failed so far. Including:
- Creating a whole new project from the beginning with the map only. I still get only grey tiles and no map. (I also tried using MapFragment and not SupportMapFragment)
- I deleted debug.keystore and even default.keyset and generated the API key a few times, still nothing worked.
Here's the code though I don't think there's anything wrong with it:
The Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pfetest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/icon_pfe"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDMsGnxt0GrU7Se5arkExJ96uLKqJWmjcQ"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.pfe.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.pfe.Couverture"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I retrieve the map using this on MainActivity in the onCreate() method
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = fm.getMap();
</code>
Still need a little try catch for this but it was working.
the layout is like this.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/m1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="1"
android:orientation="horizontal"
tools:ignore="NewApi" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="458dp"
android:layout_column="0"
android:layout_gravity="left|fill_vertical"
android:layout_row="2"
class="com.google.android.gms.maps.SupportMapFragment" />
</GridLayout>
I just want to press the compile button and get the map working, so if anyone could help with anything, I'll be very grateful!

Problem solved.
Here's what I did for those who encountered such an issue: I first removed the project and re-imported it onto eclipse, renamed the package completely, deleted the debug.keystore file and rebuilt the project to get a new one then regenerated a new API key and put it into my manifest using the new SHA1 fingerprint.
The thing is that I did all of the above several times without success and decided to leave it for a while and retried to run it every now and then (without touching the source code) and today it just worked so maybe the API key needs some time to function correctly.
Feel free to ask me about any detail if you get the same problem!

Related

Grids are displayed instead of maps when using mapview

I know there are a many questions on this topic. I have went to all of those questions and tried a lot of suggestions given in stack overflow and at other sites. But unfortunately, none has solved my problem.
When I am using MapView and MapsActivity, grid is displayed instead of maps. As suggested, I have regenerated API key and I have made sure that I have given the same package name as of my application, SHA1 key and I have enabled the Google Maps ApI for Android in the Credentials. I have given all the permissions, that are needed for maps, in Manifestfile.xml, my manifest file is as shown below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.samplemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".MapsActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyClOHCG7SBYxg1o6YdUWhn03VSqWwE1y_g"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
My layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
and my activity that extends MapActivity:
package com.example.mapsample;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class GoogleMaps_Sample extends MapActivity{
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.googlemapssample);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
When I use the above activity, grids are displayed. When I extends FragmentActivity instead of MapAcitivity and fragment instead of mapview, I have been getting an error saying unfortunately stopped and some times it says some fragment class error.
I have also installed Google API system image for the emulator I am using. I have downloaded Google Play Services too. But still, maps is not displayed to me. I have done almost everything as suggested in other questions.
What is the error or mistake in my application that is preventing maps to get displayed and that displays grid instead.
Thanks in advance.

Blank map with Google Map V2 and SupportMapFragment (and no, this is not an API key issue)

I know there are many post like this, but most of them are related to a wrong API key but this is not my case.
I know that the API key is OK, as if i change it i will get an authorization error. And from the API console, if i go to "Reports" i can see all my request.
I followed the official tutorial, i read it 10 times :
https://developers.google.com/maps/documentation/android/start
Something strange to be noticed:
When the fragment is display for the first time, the grid is blank. But if i turn off the screen, then turn it on (onResum) the map appears but it stuck, i can't move the map or use zoom controller)
And, if from my fragment, i center the map on a location, the map is centered. So forget about API key stuff.
Here is my manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.restoaparis"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#android:style/Theme.Black.NoTitleBar" >
<activity android:name=".StartActivity"
android:label="#string/app_name"
android:theme="#style/FapiaoTheme" android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_KEY"/>
</application>
Here is my layout :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Here is my fragment (as you can see i use Sherlock)
public class FragmentContact extends SherlockFragment
{
public void onActivityCreated(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.plan2 , container, false);
return view;
}
}
Of course, i got no error, no warning, from logcat.
I just got some debug message about memory , i don't think it has anything to do whith my problem.
/dev/pmem: Mapped buffer base:0x559da000 size:9539584 offset:7798784 fd:115
I add google-play-service as library of my eclipse project
Any idea ? please help me
i m nice guy, i deserve it
I've experienced similar problem and I solved my issue by adding onResume().
In my case I used MapView class.
#Override
public void onResume() {
mapView.onResume();
super.onResume();
}
You short of another meta-data element :)
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Also one more thing. You are using SupportMapFragment which is to be used for API 11 and below. Since you have a minimumSDKversion of 11 and most of the phones these days are above API 11, you might want to consider converting this to MapFragment.
Do not put a fragment inside fragment via xml. This is not supported.

Activity shows blank screen instead of map

I followed two tutorials to create an android app that displays a google map. The activity launches but there is no map visible. The zoom buttons on the side are seen though. What do I do to see the map ?
The Tutorial I used for the project structure
The Tutorial I used for the activity code
This is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.ridingo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.application.ridingo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.application.ridingo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.application.ridingo.Select_Route"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="ASDfrughiuniGDWUdhiWHdbi" />
</application>
</manifest>
The problem you describe usually happens when there is some problem with the way you defined Google Maps permissions (from a quick look at your manifest file the look OK) or from a bad configuration of the of the allowed API in the Google's API Console.
Take a look at this guide I wrote on how to configure Google Maps API V2 and make sure you do all the steps right:
Google Maps API V2
Make sure that you turn on the Google Maps V2 for Android in the console and not the one for web. another thing that looks strange in the manifest file you posted is your key (it looks too short - did you cut it in purpose) if you are not sure with the way you produced you key I would suggest you to go over this guide as well:
Google Maps API V2 key
try these steps. it worked for me.
change your main layout with this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
change your Activity to fragment activity and follow this code
public class YourActivity extends FragmentActivity
//implements GoogleMap.InfoWindowAdapter
{
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
googleMap.setMyLocationEnabled(true);
}
}
check your project properties file google play library reference must be their
target=android-10
android.library.reference.1=../google-play-services_lib
if library reference not than import library project from
yoursdkPath\sdk\extras\google\google_play_services
after you had import this library . configure this library into your project

Having problems with Google Maps for Android

I am trying to setup a basic Google Maps application for Android 2.3.3. I tried developing in Eclipse, NetBeans and IntelliJ IDEA just to name it. After failing too many times I am back to basic. Please help me with my API v1.
Currently my maps shows blank (emulator and my real device). This is my code (I tried every possible permission tag by the way):
I am signing the application with the default debug key and even when I sign it in release I still get the blank map.
All I want is to see a real map.
(By the way I am not sure if the format of the text here is right so in a nutshell I just copied the code 1-1 from here mapview v1 sample)
The manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellogooglemaps"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<application android:label="#string/app_name">
<uses-library android:name="com.google.android.maps"/>
<activity android:name="MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
The activity layout
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="BLA_BLA_BLA_GOT_A_KEY"
/>
The activity
package com.example.hellogooglemaps;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MyActivity extends MapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
If you are using MD5 for default.keystore.
Then go to Windows>show view>other>Emulator control
and send the click the send button from Emulator control(C ordinates in Decimal)
Then again run your application Map should appear with some default US location.
For getting Map in Device you need to create MD5 from your Application keystore not the default keystore.
Thanks.
The code looks fine for Google Map API V1. So there must be some problem with your key. for what I know if it's a new generated key then Google doesn't provide keys for Google Map API V1, so it must be a key for Google Map API V2 and that's the reason it doesn't work.
Please try map V2,
Use the correct map key after generating, along with the below considerations:
Internet permission. 2 . Turn on Google map for Android V2 in the developer console. 3 . Use appropriate tags in manifest, for example
below:
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxx"/>
<activity android:name="MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</application>

Android google map not loaded after inserting API key

I am trying to load google map in mapview. I have inserted google API key in main.xml.
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="My.google.mao"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".GmapActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
This is main.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Api key"/>
//Api key has been inserted
Only boxes are being loaded in mapview, can anyone solve my problem?
Most likely reason is mixing up debug key and release key, as the signitures are different the keys are different, you need to get both. There is a post on programaticaly selecting the right key
This problem comes in 2 situations
Give these uses permissons also Acces core location, access fine location
and one more thing is you ar enot given correct API key so generate properly tryagain,
That api key will work only in your system
If you have any problem with generating api key i will help you

Categories

Resources