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
Related
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.
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
After a lot of research to resolve my issue, I have to ask. Everything is set up but the map won't show. The error is:
08-16 20:31:49.473: E/Google Maps Android API(10864): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
I am running the Map on Debug mode (I've also tried by installing the .apk into the device and running it) and the same thing happens - no Map.
I have checked Api key
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
... >
<permission
android:name="com.my_package_name.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.my_package_name.permission.MAPS_RECEIVE" />
<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" />
<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.maps.v2.API_KEY"
android:value="AIzaSyCEH*************************" />
</application>
</manifest>
Activity
public class Home extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
It's an authentication issue, it's likely you haven't setup your API key correctly, using your SHA1 fingerprint.
Take a look at this
Activate these Services in the Google Console:
Google Maps Android API v2
Then, recreate the API key and the Maps should work - they did for me.
Put this into your manifest.
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"></meta-data>
Also check that the Consent Screen (on Google Developer Console Website > Settings) has your email address and product name.
I am running sample code that is provided on Google Map Documentation for Google Map Api v2 (https://developers.google.com/maps/documentation/android/start#specify_settings_in_the_application_manifest).
The code run successfully but Map is not loaded on the device. Only white screen is shown on the device. I am using 4.0.3 version Android device.
1) I enabled service for the project.
2) Generated key:
3) "google-play-services_lib" as Library in project:
4) Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.mapdemo.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.ACCESS_NETWORK_STATE" />
<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="AIzaSyCvZrhQ8YBfyYBvTic3DSdu2O06nAmhpg4" />
<activity
android:name="com.example.mapdemo.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>
</application>
</manifest>
5) Activity:
package com.example.mapdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
6) 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.MapFragment"/>
Use Fragment activity
eg:
public class Maps extends FragmentActivity {
GoogleMap map;
double lat;
double lan;
boolean flag = false;
// private LocationManager lm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapptry);
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
}
Change ur map.xml to
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
EDIT
Got to do this also
import android.support.v4.app.FragmentActivity;
Before you do this Right click project->properties->buildpath->java build path -> libraries .. then click on add external jars
the go to
user\android-sdks\extras\android\support\v4
and select android-support-v4.jar
PS: Do all this provided your API key is correct . If you API key is wrong then also it shows only a white screen
try to add
GoogleMap googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
and replace your xml with
<?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"
/>
you have added the following code outside application tag instead put it inside the tag
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
hope this might help someone who is facing the same problem
May be this problem with API key or you just check your SHA1 fingerprint in your project api console(https://console.developers.google.com/project) and your eclipse Windows -> Preferences -> Android -> Build are same, other wise just update the SHA1 from console to build path or vice versa.
Most probably your problem will be solved when you make sure below mentioned things:
Activate Google Map API
Use correct package name while generating API Key (in my case this was the mistake) .. and this seems problem to your case also as package name appears to be wrong (com.example.mapdemo)
Make Sure you are using the correct keystore file for generating the SHA1
Hope this will be helpful.
To maintain security for the system and users, Android requires apps to request permission before the apps can use certain system data and features. Depending on how sensitive the area is, the system may grant the permission automatically, or it may ask the user to approve the request.
https://developer.android.com/guide/topics/permissions/index.html
In case anyone else is as dumb as me... make sure the device you are testing on is connected to WiFi...
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