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
Related
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?
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.
I'm trying to develop android app which has two screens, and in the second I want google map to be shown...I read everything about this problem everywhere I could find and I did all steps to get API key, I edited Manifest xml file, the second screen xml file (where i want google maps)...provided API key, I set it in previously mentioned xml files, allowed using of internet etc... and still..the problem persists. If anynone has any idea what could be a problem, please answer !
Here's some code i wrote:
Manifest(xml) file:
<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="com.example.androidgui.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>
<activity android:name=".Mapa"
android:label="#string/screen2Title">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
</activity>
</application>
xml file of screen i want google maps to be displayed at:
<?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.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="API_KEY"
android:clickable="true"
/>
Java file of the screen :
package com.example.androidgui;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class Mapa extends MapActivity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondscreen);
MapView mapview = (MapView) findViewById(R.id.mapview);
mapview.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
You are trying to use deprecated Google Maps Android API v1 and mix it with Google Maps Android API v2 key.
The easiest way to start with v2 is removing all the code you have related to maps and following instructions here: https://developers.google.com/maps/documentation/android/start
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>
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....