Having problems with Google Maps for Android - 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>

Related

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

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!

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

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

Google map Activity

I want to use map activity in my application, I don't know how to deal with Google Map API v2.
How to generate an API key and All? Right now my application is not working with normal intent code.
Intent intent = new Intent(this,GeoMap.class);
startActivity(intent);
Android manifest entry like this
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".HomeTab" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomeActivity" />
<activity android:name=".SearchActivity" />
<activity android:name=".GeoMap" >
</activity>
</application>
</manifest>
please help me.
Thank you.
Before asking something I think you should check the FAQ.
When you ask something ask Google first,it should give you some answer.
Anyways check this step by step tutorial for MAP API V2: Google Maps API v2 for Android
And for obtaining an API Key this simple tool might help you:
JavaKeytoolGUI Beta 2

Simple Maps View Doesn't Work

I have a problem while creating a simple google maps view. Below you can find my code:
The manifest:
<uses-sdk
android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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="AIzaSyB0zPyFFyQ_sCVmMjj6pgNqvqKg3zHGMSs"/>
<activity
android:name="com.example.maptest.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.EMBED"/>
<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>
In Java File:
public class MainActivity extends MapActivity {
private MapView mapView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView)findViewById(R.id.map);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
In the XML File:
<com.google.android.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:apiKey="AIzaSyB0zPyFFyQ_sCVmMjj6pgNqvqKg3zHGMSs"
android:clickable="true" >
</com.google.android.maps.MapView>
The result is a starting app, witch shows just gray area instead of the map, but with the typical google-icon in the corner.
I know the most common problem is an incorrect API key, but I checked it often and the key is correct.
Maybe someone has a suggestion?
The problem is that you are using a key for the V2 API (judging from the comment in your manifest), but your implementation uses the V1 API. You basically have both API versions mixed up here. The V1 API requires an appropriate V1 API key to be placed as an attribute for the MapView in the XML layout. The V2 API requires the key to be placed in the manifest as you have done. Furthermore, the V2 API requires varous other stuff to be added into the manifest as well.
While you're using the V1 API, you need to obtain a V1 API key (which you can do until April, because it's deprecated). Alternatively, switch to using the V2 API which obviously you'd be encouraged to do (but watch out for the fact that it requires a later OpenGL version that isn't supported on some 2.2 devices).
I would suggest you follow the V2 API tutorial closely: V2 Maps API

Categories

Resources