I'm developing a simple Google Maps app for Android. I'm using Eclipse and an Android Virtual Device. When running the app, no tiles are shown, and I get the message "Couldn't get connection factory client".
I've read and looks like it is a bug, but some people say they got their apps working. I've tried using API 1.6, 2.1, 2.2 over my virtual device (2.2) and none of them work.
I got my API key from the MD5 obtained from the debug.keystore.
How can I solve the problem? I just found people with the same problem, but any solutions.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uniovi.pfc"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".SimpleMap2Activity"
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.ACCESS_FINE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<user-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
</user-permission>
</manifest>
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="#+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0YSU8-p-YkHYQ2lit-vAsh2U0jW5zV3l_YQVlvw" />
</LinearLayout>
Code:
package uniovi.pfc;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
public class SimpleMap2Activity extends MapActivity {
private MapView mapView=null;
private MapController mapController=null;
private GeoPoint geoPoint=null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview1);
mapController = mapView.getController();
String coordinates[] = { "40.747778", "-73.985556" };
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mapController.animateTo(geoPoint);
mapController.setZoom(5);
mapView.invalidate();
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_I:
mapController.zoomIn();
break;
case KeyEvent.KEYCODE_O:
mapController.zoomOut();
break;
}
return super.onKeyDown(keyCode, event);
}
}
Finally, the problem was the maps apiKey. This topic is not very well explained over the internet.
Shortly, I would explain as following:
To use maps into an Android Virtual Machine, you use debug.keystore
To use maps into a real Android device, you need to create a key into a new keystore. Eclipse can do it for you if you right-click the project and export as a signed apk.
In both cases, you need to go to console, and execute a Java tool called keytool.exe at java jdk /bin/ folder.
If keytool gives you the SHA1 code and not the MD5, the problem can be that you are using Java 7. Add -v parameter to the keytool call to enter verbose mode, and you'll get also the MD5 Google asks you for.
Related
NB - I've been through this site with a fine toothed comb and can't find an answer that helps me. Though, this seems to be a common problem for whatever reason.
I'm a proper noob at Java, and I'm currently teaching myself. I'm working towards GeoFencing, but obviously need to learn about including Maps in my app first. I've tried so many things but I can't get a working Map to display, instead I get a blank outline of where a map should go and then some zoom buttons and a Google Logo. Can anyone point out what I'm doing wrong?
For the record:
I'm testing on Stock Galaxy S3 i9300 - 4.3
Included Google Play Services Library
Included android.support.v4.jar
Tried two different API keys
Tried multiple 'Project Build Targets' (both Android and Google ones_
I am however using the API key generated from degug.keystore. Would that cause a problem.
Thanks in advance :)
Manifest:
`
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="18" />
<permission
android:name="com.example.geofence1.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.geofence1.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"/>
<!-- 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"
/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyB81f5fwV0MPK9ZA6Y-ESt2Rq_0T76xF7I"/>
<activity
android:name="com.example.geofence1.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>`
Main_Activity.java:
package com.example.geofence1;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class MainActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
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 wrote a simple google map app,it runs fine with emulator on my pc but fails in "spice mi-720".
note-1)got the api key and wrote it at main.xml
2)make the .apk file using debug.keystore
3)set the tab to allow non market app to install in settings
the apk is installed in the tab successfully but showing "the program is stopped unexpectedly".i have given the code snippet below.
pls help.
activity
--------
public class test extends MapActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
main.xml
----------
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="0SlULcexiGYLloibzAUWGXb5AeQHk7Lnnf365sQ" />
</RelativeLayout>
manifest file
-----------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tets"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".test"
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>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Add the mapView in your activity
MapView mp;
MapController mc;
GeoPoint gp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mp=(MapView)findViewById(R.id.map_view);
mp.displayZoomControls(true);
mp.setBuiltInZoomControls(true);
double lat= 40.8;
double longi =-96.6666;
gp=new GeoPoint((int)(lat* 1E6), (int)(longi*1E6));
mc=mp.getController();
mc.animateTo(gp);
mc.setZoom(14);
}
I would suspect that the spice mi720 tablet does not contain the google APIs. Android Devices on their own do not have the market app, the gmail app and some other apps, and they also do not include the google maps api. The google maps API is an add on that only phones and tablets get that are approved by google. Many cheap tablets are not approved by google.
Your App is crashing because it tries to load a class that is not available on the device. The only solution to this is to check if the maps framework is available and if it is not show an error message to the user or try to open a replacement using other map kits or a web based google maps solution.
When I load my MapView application, the MapView only displays the grey grid lines.
Here is my Code:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0aOphT3vlZFVSL1HZ2Vg-RmIDhH0nPlp8e7gJrg"/>
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andoid.googlemaps"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps"></uses-library>
<activity android:name=".GMapsActivity"
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-sdk android:minSdkVersion="1" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Activity:
package com.andoid.googlemaps;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class GMapsActivity extends MapActivity {
private MapView mapView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Proxy Settings*/
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "proxy.example.com");
System.setProperty("http.proxyPort", "8080");
setContentView(R.layout.main);
mapView=(MapView)findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
Thanks in advance for any help...
See the following link on displaying google map. This may help you
Tutorial on How to use Google map
The API key used for the map depends on the certificate used to sign your application.
You must follow the following instructions to get a valid API key.
The Android Maps API lets you embed Google Maps in your own Android applications. A single Maps API key is valid for all applications signed by a single certificate. See this documentation page for more information about application signing. To get a Maps API key for your certificate, you will need to provide its the certificate's fingerprint. This can be obtained using Keytool. For example, on Linux or Mac OSX, you would examine your debug keystore like this:
See Sign Up for the Android Maps API.
This often means that you need a key for debug-builds and another for release-builds (signed application package for Android market for example).
After a long time its worked. But still not got where was the problem actually,nothing i changed just i shared debug.keystore with my friend and its worked. Any way thanks for the reply...
i am unable to view maps on the emulator. I am under proxy internet connection, I also set the proxy via GUI and also have set api Key alongwith the perimissions and library.
here's my code:
package com.example.MyMapActivity;
import org.apache.http.HttpHost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
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;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DefaultHttpClient client = new DefaultHttpClient();
String proxyHost = android.net.Proxy.getHost(this);
if (proxyHost !=null) {
int proxyPort = android.net.Proxy.getPort(this);
HttpHost proxy = new HttpHost("*********", ***);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
//mapview = (MapView)findViewById(R.id.mapview);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
// this method must return true if your app returns driving directions , else return false
return false;
}
}
The Layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="***********"> </com.google.android.maps.MapView>
The mainfest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.MyMapActivity"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps"></uses-library>
<activity android:name=".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>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name ="android.permission.ACCESS_COARSE_LOCATION"/>
I faced the same problem and after a long time I found that I made a mistake in one digit while copying the md5, so the generator produced me a wrong api key. My suggestion is to make sure first that you have copied the correct md5.
If the emulator does not have Google Maps installed on it you can't use MapView or any other maps related activity.
You need need to make sure you create an emulator image which has the Google APIs available.
If the mapview is displayed but no maptiles are loaded it could be this bug ( Google Maps fails via mandatory web proxy) that is reported in the bug database from google. Read all the information about the issue carefully. It is very possible that this is an error on your side that you will never discover because you think it is googles fault.
Test the app somewhere without a proxy to confirm that it is working there.