Google Maps Android API v2 stopped working - android

Google maps was working on a published app and now for some reason it has just stopped displaying the map. Here is the manifest:
<manifest
.....
<permission
android:name="com.x.x.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.x.x.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
.....
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/map_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="4030500" />
</application>
I have got the debug and release SHA-1 keys from the debug and release store and put them on the Google Maps Android API V2 and have put the API key in to the manifest (hardcoded and in strings.xml).
Here is the layout:
<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 the how I try to access the SupportMapFragment from the fragment being displayed:
private void setUpMapIfNeeded()
{
SupportMapFragment fragment = (SupportMapFragment)fManager.findFragmentById(R.id.map);
if (fragment != null)
{
mMap = fragment.getMap();
}
// Check if we were successful in obtaining the map.
if (mMap != null)
setUpMap();
}
However fragment always returns null. At one point I was getting the failed to Authorise message, but currently I dont see that. Only a blank map.
Update:
It does not seem to be a problem with the keys, it is to do with
android:name="com.google.android.gms.maps.SupportMapFragment"
in the layout file. When I try to get the fragment by id it returns null. The frustrating thing is that I have created a test project where the set up is basically identical and it works. Yet when I try the same code in this project it is not working. Both projects are pointing at the same Google Play Services library project and they both point to the Support Library v4. Even the manifest has the same entries. Also, if I replace SupportMapFragment with MapFragment it works ok.

if everything is the same (you dont change the package name, or the key, and you are using the debug sha1 for the debug api key, ),and it stoped working, i would say that you have a conflict with the version of play services.
try removing the hardcoded version here
<meta-data
android:name="com.google.android.gms.version"
android:value="4030500" />
probably that version is not working with your google play services version (you can chek the actual version in google-play-services_lib>res>values>version.xml). check that the jar you are using is exactly that version, and change it if its not. Also, if you check the log cat, you can see something like
Caused by: java.lang.IllegalStateException: The meta-data tag in your
app's AndroidManifest.xml does not have the right value.
i would change that meta-data to
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
that is what google recommends and also follow the other advises int that page
anyways, if you take a look at logcat (or post it here) probably we can get a clue on the logs around setUpMapIfNeeded()

I'm not sure why it stopped working when it had worked previously, but this was the solution:
SupportMapFragment - Binary xml file line #2: Error inflating class fragment

Well according to the GoogleMap Android API setup, it says
<?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.MapFragment"/>
which is what I did and works. I've not used suppotMapFragment myself but from this link here, the element seems to be
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

You probably checked most of the things already (as I did).
My map worked perfectly with the debug keystore, but went blank when I switched to the signed key.
My problem was solved when I created an Api Key (with debug key+project package name) in one google account to use during development time....
and I created another Signed Api Key (signed keystore+project package name) on another google account.
Apparently you cannot have more than one API key for the same package name (even if the keystore is different!) on the same google account.

This can be the cause of your SHA1 certificate changing, what you have to do is get the new SHA1 and edit it in your Google Console where you get the Maps API, then try to regenerate a new API and give it like 5 minutes to work properly.

Related

Trouble In Implementing Google Maps In the Application

i am Trying to Implement Google Maps in my Application, i have Fragment the code like this :
map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
MapsInitializer.initialize(getActivity());
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
if(resultCode != ConnectionResult.SUCCESS)
{
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, getActivity(),
69);
dialog.setCancelable(false);
// dialog.setOnDismissListener(getOnDismissListener());
dialog.show();
}
Log.d("GooglePlayServicesUtil Check", "Result is: " + resultCode);
}
and my XML :
<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">
<fragment
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="AIzaSyABcmhLoZuEuU6eMSlwWGA1_IrEKR3L5n8"
/>
</RelativeLayout>
when the app Runs, i Can see The map Borders, and Zoomin / Zoomout Button , But i Get 2 Errors , First
Could not find class 'com.google.android.gms.location.internal.ParcelableGeofence
referenced from method glt.a
and after a few seconds I get This Error :
Failed to load map. Error contacting Google servers. This is probably an
authentication issue (but could be due to network errors).
I Have Just ReCreated my Key by Going to The SHA1 Finger Print From Eclipse's Windows,Preferences,Android,Build,SHA1 FingerPrint and Creating In Google :
API Project / APIS & AUTH / Credentials / Create New Key / Android Key
Like this:
2A:61:79:6F:3D:41:9E:C9:81:F5:C0:49:EE:F8:CA:09:04:0C:3A:AE;com.lifemate.lmmessenger.mapspack
(My Class is com.lifemate.lmmessenger.mapspack.maps) and here is My Manifest :
<uses-permission
android:name="com.lifemate.lmmessenger.mapspack.maps.permission.MAPS_RECEIVE"/>
<IS THE UPPER ONE RIGHT? (My Class is the maps.Java>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<Application ...
<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="AIzaSyABcmhLoZuEuU6eMSlwWGA1_IrEKR3L5n8" />
I Have Added the Google Play Services Jar and Project to my Application, Am i Missing Some thing Guys ?
If you using Android Key with namespace you must use the signed application (generate apk with key)
If you use application to testing just delete this and leave blank:
2A:61:79:6F:3D:41:9E:C9:81:F5:C0:49:EE:F8:CA:09:04:0C:3A:AE;com.lifemate.lmmessenger.mapspack

MapView google maps api V2 looks blank only display grid with +/- button

I do all the steps, I add google-play-sevices to my project,I do everything .I don't what's the problems.I create my api key using debug certificate fingerprint using SHA1 fingerprint in eclipse windows>preferences>android; I'm using lg E400 con android 2.3.6
MainActivity:
import android.os.Bundle;
import android.app.Activity;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
public class MainActivity extends Activity {
GoogleMap map;
MapView m;
com.google.android.gms.maps.Projection projection;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m=(MapView) findViewById(R.id.mapview);
m.onCreate(savedInstanceState);
map = m.getMap();
if (map != null) {
// The Map is verified. It is now safe to manipulate the map.
}else{
// check if google play service in the device is not available or out-dated.
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// nothing anymore, cuz android will take care of the rest (to remind user to update google play service).
}
try{map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
}catch(Exception ex){ex.printStackTrace();}
MapsInitializer.initialize(this);
}
#Override
public void onResume() {
super.onResume();
m.onResume();
}
#Override
public void onDestroy() {
super.onDestroy();
m.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
m.onLowMemory();
}
#Override
public void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
m.onSaveInstanceState(outState);
}
}
layout:
<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" >
<com.google.android.gms.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.voicesee"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<permission
android:name="com.example.voicesee.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.voicesee.permission.MAPS_RECEIVE" />
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<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:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.voicesee.MainActivity"
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="AIzaSyAguDjIFiVWi18ll7Yh0oa8C7hWju1PUzI"/>
</application>
thanks for help!!
I had a similar problem, my issue was because I was picking the wrong debug keystore. I am working with an ubuntu machine. Since I opened eclipse as root, the default keystore in eclipse was located in my root folder(/root/.android/.android/debug.keystore) whiles I was creating the api key with the debug keystore from my user folder. I have added a link to the answered question:
Google Maps V2 shows blank screen on android 2.2
are you sure: your project in Google Console turn on the
Google Maps Android API v2
First, I don't understand why are you using a MapView when you are placing you map in the Acitivity because it's the harder way to display the map when you do so, Google's documentation states:
For a simpler method of displaying a Map use MapFragment (or SupportMapFragment) if you are looking to target earlier platforms.
Second, If you already do so, then you made some mistakes in implementing it because you place the:
MapsInitializer.initialize(this);
method in the wrong place, as the documentation states:
Use this class to initialize the Google Maps Android API if features need to be used before obtaining a map. It must be called because some classes such as BitmapDescriptorFactory and CameraUpdateFactory need to be initialized.
You will want to use a fragment to encase your map, and fragments are only supported by Android API levels 11 and up (3.0 and up). This is likely the cause of your problem.
As mentioned here, you need to use SupportMapFragment for your API version.
Here is the link to learn how to use it.
If that doesn't work, my guess is the API key. We had a situation before where the grid and the zoom buttons loaded and not the map, and the key was the culprit. I'd walk through the steps here to make sure you have done everything correctly (including using google play services)
In my code , i change mapview with supportMapfragment , i delete my previous debug.keytool and rebuilt it then i delete my old apikey and create a new key .It seems that my problem was the connection with google play service because it works after adding GooglePlayServicesUtil.isGooglePlayServicesAvailable() and verify the connection with google play services before calling setContentview()
once check your api key in manifest and SHA key of your application.. You can create new one by going to console.developers.google.com.
To see SHA key eclipse go to
--> windows>preferences>select android on left panel>click on build
To see SHA key android studio
see this link How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?

Null GoogleMap/Crashing when implementing Google Maps Android API v2 (In Xamarin)

I'm currently struggling on an extremely basic implementation of the aforementioned API using Xamarin. Most of the manifest was copied from these tutorials which I cross-referenced:
http://docs.xamarin.com/guides/android/platform_features/maps_and_location/part_2_-_maps_api/
https://developers.google.com/maps/documentation/android/start#obtain_a_google_maps_api_key
The Map property of my MapFragment is null and I can't figure out why. I've successfully generated an API key, and specified my package permissions, including adding the SHA-1 fingerprint/package name to the API console. Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="#string/package_name">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="18" />
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<!-- Google Maps for Android v2 requires OpenGL ES v2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<!-- We need to be able to download map tiles and access Google Play Services-->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allow the application to access Google web-based services. -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps for Android v2 will cache map tiles on external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:label="#string/app_name">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="#string/api_key_android" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
MAPS_RECIEVE was a permission in the tutorial, but I found that it is now obsolete here and thus omitted it:
Android Map V2 - Why MAPS_RECEIVE permission
READ_GSERVICES is detected as an unknown permission.
And here is my code:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
//Create the user interface in code
LinearLayout layout = new LinearLayout (this);
layout.Orientation = Orientation.Vertical;
TextView txtKey = new TextView(this);
txtKey.Text = "Your key is " + GetString(Resource.String.api_key_android);
TextView txtNullCheck = new TextView (this);
txtNullCheck.Text = "Map not null";
//Create MapFragment and add it to this UI
MapFragment myMapFrag = MapFragment.NewInstance();
if (myMapFrag.Map != null) {
FragmentTransaction fragTx = FragmentManager.BeginTransaction();
fragTx.Add(layout.Id, myMapFrag);
fragTx.Commit();
}
else
{
txtNullCheck.Text = "Null GoogleMap";
}
layout.AddView(txtKey);
layout.AddView(txtNullCheck);
SetContentView(layout);
}
Interestingly, if I omit the null check and just add the MapFragment the app will give me the message "Unfortunately, this app has stopped working" after a few seconds. Otherwise I will only get a null myMapFrag.Map and the MapFragment will not function as desired.
I'm currently testing this on a Galaxy Note 3.
I've been stumped on this for quite a while, and the documentation I've found hasn't been very helpful. So any help will be very appreciated!
Thanks,
~F

Android: Google Maps not displaying

I'm trying to get a google map to display. I can see the background (light gray background, small tiles, Google logo in the lower left), so I know that I'm close. However, there is no actual map displayed. In the LogCat, I see this message repeating over and over:
05-14 13:28:17.926: W/System.err(27458): at
android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
I'm using Google maps api 2 with a tethered phone for testing that is running 2.3.4.
Anyone know what might be causing this? Thanks!
package com.example.maptest;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class MyMapActivity extends MapActivity {
private MapView mapView;
private MapController mapController;
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
mapView = (MapView)findViewById(R.id.map_view);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maptest"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="com.example.maptest.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.example.maptest.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" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:required="true" android:name="com.google.android.maps" />
<activity
android:name="com.example.maptest.MyMapActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxx"/>
</application>
</manifest>
This problem is usually related to the map API key used to sign manifest. Take a look at this post and this one which describe the same error you are experiencing. In both cases it is because the API key they used was created with the wrong keystore. You need to make sure you use your debug keystore when you create an API key in the Google API console if you are going to be testing from eclipse.
Basically you are mixing deprecated Android API v1 with the new API v2.
The easiest way to migrate is to remove all v1 related code and start from scratch, following this link: https://developers.google.com/maps/documentation/android/start
go to developper console enable maps api for your device and then copy your key and paste in values->google_maps_api.xml . It works
Use Android key(auto created by google service) if on android devices
After days of struggle, I found the issue.
In my manifest I had the key value stored in an xml file and it didn't work.
Now i have
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzxxxxxxxxxxxxxxxxxxxxxxxkey" /> and it works.
Just removed the xml file...
Hope it helps!
If you have several packages in your app beware when you create the API key you must use the package name that included in top of the android mainfest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
**package="com.xxx.xxx"**
android:versionCode="1"
android:versionName="1.0" >
well actually I had lived this problem and it makes me crazy. after I found the solution. very simple:
1- in your project, google_maps_api.xml just check the web link is for your package name, if your package name exist and correct. go to page and get the key
To get one, follow this link, follow the directions and press "Create"
at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=...
2- just create new gooogle maps activity project get the SHA-1 code.
dont forget SHA-1 code is same in your other project but web link is uniqu for each your program
I had the same problem. The problem was in my manifest file. Check if the google maps key you have stored IN STRING.xml and google maps key in google_maps_api.xml does not have same name.
One most probable reason for this is you have not added API key in the project manifest file. Simplest way to fix this is go to the "google_maps_api.xml" file and copy the link in the file and paste it in the browser. Click on the create button in the link and copy the api key that is being generated after that and paste it in the AndroidManifest.xml in the place of "Your Api Key" which is inside the meta-data tag, compile the project this will fix the issue.
May be this is because of the Google API key you have to make put google_maps_api.xml file in the values folder and paste the correct API key in it.
and also you have to put this code in AndroidManifest.xml file
<application>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
</application>
If above all answers do not work at all .Then use another Emulator . It worked for me.
If you create the key using the link in google_maps_api.xml it sets the package name of the MapActivity and not the package name of the application (defined in manifest).
Make sure you have the same package name console.developers.google.com as in application manifest.
It can happen because of your key has not restricted yet. after you created your API key, you should restrict the key.
https://console.cloud.google.com/apis/credentials

My android app is showing only grid not map

I am new at Android. I have been trying from many days to make very basic google map application but unable to complete it yet...
There are no errors in code, emulator running fine from terminal, Map key also fine but still I am unable to see the map. When I run my app only grid appears and map is not displayed. Here is the code, can any body please help me.
i am using eclipse juno 4.2.1 api level 17 and i want to show map using google map api v2
My code is here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemap"
android:versionCode="1"
android:versionName="2.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.googlemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.mapdemo.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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="[API_KEY]"/>
<!-- <activity
android:name="com.example.googlemap.MainActivity"
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>
main.xml
<?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"
class="com.google.android.gms.maps.MapFragment"/>
MainActivity.java
package com.example.googlemap;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
protected boolean isRouteDisplayed() {
return false;
}
}
Your Manifest file is using Maps V2 and layout and Activity are using Maps V1. You are generating Maps API key using Maps V2 api key generation procedure and setting the same to Maps V1 MapView. So It will not display as it treat a wrong API Key.
Either you generate API key in V1 Key Generation Procedure or else use google-play-services_lib project and change the MapView and other Classes.
First, in your manifest file, modify this part into this below.
<activity
android:name="com.example.googlemap.MainActivity"
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" />
Why did you block this part? Please make this part activate right now.
###
Second,please modify your main.xml into this below; You MUST specify if the layout file name is "main.xml" or "activity_main.xml".
<?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"
class="com.google.android.gms.maps.SupportMapFragment"/>
You must use the above code. Because you set [android:minSdkVersion="8"] in your manifest file. Your main.xml is only useful for testing your settings in an application targeting Android API 12 or later .
###
Third, please modify your MainActivity,java into this below;
public class MianActivity extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
And in Eclipse, press Ctrl + Shift + O (alphabet) on your Keyboard and perform "organize imports" and then several classes will be imported automatically.
This code from #1 to #3 above is the standard basic code format to be able to see Google Maps on your real handset using new Google Maps API version 2. This code will show you a map and a marker on the map.
###
Four. The most important thing is to add two libraries to your project : one is Google Play service libs, the other is Android-support-v4.
HOW to add this two libraries to your project, see this document : Click here.
If you can not set two libraries, you can not see the map on your real handset.
###
Five, Try to run your project just on your real device(handset), not on the emulator in Eclipse. Because we can not see the map using the new Google Maps API v2 supported with Google Play service on the emulator, which is Google's official document :click here.
###
I hope you will see Google map on your real handset.
I also had a similar problem. This worked for me!
Go to Google API Console, where the API key was generated.
Click on services (appears on options in left).
Hover and search for Google Maps Android API v2.
Enable it (initially it was off hence only grey tiles appeared).
There are no errors in code, emulator running fine from terminal
Great ! But Window > Show View > Other > Android > Logcat !
The application may not crash but the Map API is telling you why the map can not be displayed in the logs.
To be sure you did well:
To implement the new Google Map API, Google released a non-complete guide. You can find it here.
I say non-complete because they do not clearly explain the setup of Google Play Services, but they do here.
Make sure you have this setup:
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
or whatever type you want....

Categories

Resources