0

I am trying this for about 4 hours but not happens. Trying to develop an app to display a particular location in google map.

Did the following code:

GooglemapsActivity.java

package com.example.gps2;

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;

public class GooglemapsActivity extends MapActivity {

private MapView mapView;
private MapController mc;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapView);
    mc = mapView.getController();

    String coordinates[] = {"30", "71"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    GeoPoint p = new GeoPoint(
            (int) (lat * 1E6),
            (int) (lng * 1E6));

    mc.animateTo(p);
    mc.setZoom(7);
    mapView.invalidate();
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
}

main.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/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="AIzaSyBbGgoanloghVHc_rSHmS_yBG1Y7Ho7rsM"
    />
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gps2"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<permission
    android:name="com.example.gps2.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:name="android.hardware.location"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location.network"
    android:required="false" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
    android:name="android.hardware.wifi"
    android:required="false" />
<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" >
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:name="com.example.gps2.GooglemapsActivity"
        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 am using Google API 18 (platform 4.3)

I have generated the android Key using the SHA1 code "B5:EE:A3:80:7C:11:16:21:D7:EC:95:D1:FE:03:79:3D:4F:92:2D:73;com.example.gps2"

I am using the AVD with target Google API 18.

After all this the Google map is not getting displayed. Just getting the screen with the grids. Please suggest where I need to fix to make it work.

logCat:

01-12 07:01:20.958: D/dalvikvm(993): GC_FOR_ALLOC freed 533K, 18% free 3207K/3864K, paused 51ms, total 56ms
01-12 07:01:20.968: W/System.err(993): java.lang.IllegalStateException: Connection pool shut down.
01-12 07:01:20.968: W/System.err(993):  at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:284)
01-12 07:01:20.968: W/System.err(993):  at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:238)
01-12 07:01:20.968: W/System.err(993):  at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:176)
01-12 07:01:20.968: W/System.err(993):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:326)
01-12 07:01:20.968: W/System.err(993):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-12 07:01:20.968: W/System.err(993):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-12 07:01:20.968: W/System.err(993):  at android_maps_conflict_avoidance.com.google.common.io.android.AndroidHttpClient.execute(AndroidHttpClient.java:246)
01-12 07:01:20.978: W/System.err(993):  at android_maps_conflict_avoidance.com.google.common.io.android.GoogleHttpClient.executeWithoutRewriting(GoogleHttpClient.java:129)
01-12 07:01:20.978: W/System.err(993):  at android_maps_conflict_avoidance.com.google.common.io.android.GoogleHttpClient.execute(GoogleHttpClient.java:189)
01-12 07:01:20.978: W/System.err(993):  at android_maps_conflict_avoidance.com.google.common.io.android.GoogleHttpClient.execute(GoogleHttpClient.java:242)
01-12 07:01:20.978: W/System.err(993):  at android_maps_conflict_avoidance.com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.getResponse(AndroidHttpConnectionFactory.java:132)
01-12 07:01:20.978: W/System.err(993):  at android_maps_conflict_avoidance.com.google.common.io.android.AndroidHttpConnectionFactory$AndroidGoogleHttpConnection.openDataInputStream(AndroidHttpConnectionFactory.java:153)
01-12 07:01:20.978: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:922)
01-12 07:01:20.978: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
01-12 07:01:20.988: W/System.err(993):  at java.lang.Thread.run(Thread.java:841)
01-12 07:01:31.467: W/MapActivity(993): Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@41702a70
01-12 07:01:31.507: V/MapActivity(993): Recycling map object.
01-12 07:01:32.387: I/MapActivity(993): Handling network change notification:CONNECTED
01-12 07:01:32.387: E/MapActivity(993): Couldn't get connection factory client
01-12 07:01:51.737: W/System.err(993): IOException processing: 26
01-12 07:01:51.737: W/System.err(993): java.io.IOException: Server returned: 3
01-12 07:01:51.748: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
01-12 07:01:51.758: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
01-12 07:01:51.758: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
01-12 07:01:51.758: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
01-12 07:01:51.758: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
01-12 07:01:51.758: W/System.err(993):  at java.lang.Thread.run(Thread.java:841)
01-12 07:02:15.378: W/System.err(993): IOException processing: 26
01-12 07:02:15.378: W/System.err(993): java.io.IOException: Server returned: 3
01-12 07:02:15.378: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
01-12 07:02:15.389: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
01-12 07:02:15.389: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
01-12 07:02:15.389: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
01-12 07:02:15.398: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
01-12 07:02:15.398: W/System.err(993):  at java.lang.Thread.run(Thread.java:841)
01-12 07:02:44.837: W/System.err(993): IOException processing: 26
01-12 07:02:44.837: W/System.err(993): java.io.IOException: Server returned: 3
01-12 07:02:44.837: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
01-12 07:02:44.847: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
01-12 07:02:44.857: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
01-12 07:02:44.857: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
01-12 07:02:44.857: W/System.err(993):  at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
01-12 07:02:44.867: W/System.err(993):  at java.lang.Thread.run(Thread.java:841)

Thanks...

twlkyao
  • 14,302
  • 7
  • 27
  • 44
saptarshi
  • 97
  • 1
  • 14

4 Answers4

2

You are making a whole mess of how you should implement the Google Maps API V2 in your application and confusing lots of stuff with API V1 implementation.

First, to show google map in an Activity you would usually use a MapFragment or SupportMapFragment in you case (API < 11), so you should add this in you xml layout of the activity:

 <fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Next, you should inherit from FramgnetActivity in API V2 as oppose to MapActivity from API V1, so you should do this:

public class MapActivity extends FragmentActivity {
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_layout);
    }
}

Finally as already mentioned you should provide you API key in your manifest file, and not in your xml file. So put this in the manifest under the application tag scope:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

and this:

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your Google Maps API V2 Key" />

You can find a detailed explanation in this blog post I wrote on this topic:

Google Maps API V2 Guide

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • Thanks....it helped.... But now I am facing another problem. I am using Genymotion virtual device and configured it with eclipse. When I am running my app from eclipse it is working very smoothly. After that when I am creating .apk file and installing it separately on the genymotion AVD it is not working. I have turned on the GPS. Please help! – saptarshi Jan 13 '14 at 03:51
  • what happens if you install it on a real device? mostly likely the map won't work if you haven't registered the release.key that you are using to create the apk file via the Google API Console. – Emil Adz Jan 13 '14 at 12:18
  • That is the reason...I am using the debug key....I need to get the release certificate fingerprint. Could you please give me the procedure of getting the release key with example. Thanks... – saptarshi Jan 13 '14 at 12:51
  • I don't have such a procedure... but it's similar to what you did with the debug key, after you sign your application you will produce a key with a passcode.. just use the keytool to get the SHA1 fingerprint out of it and register it via the console – Emil Adz Jan 13 '14 at 12:59
0
<permission
    android:name="your_package_name.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

try to place your package name....

vinay Maneti
  • 1,447
  • 1
  • 23
  • 31
  • I/Choreographer(1404): Skipped 32 frames! The application may be doing too much work on its main thread. W/MapActivity(1404): Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@416fe408 01-12 07:15:49.617: V/MapActivity(1404): Recycling map object. 01-12 07:15:50.247: I/MapActivity(1404): Handling network change notification:CONNECTED E/MapActivity(1404): Couldn't get connection factory client I/Choreographer(1404): Skipped 54 frames! The application may be doing too much work on its main thread. – saptarshi Jan 12 '14 at 12:18
  • and have you added Google play service as a lib. project refer for you project... – vinay Maneti Jan 12 '14 at 12:50
  • http://stackoverflow.com/questions/10960252/mapactivity-couldnt-get-connection-factory-client – vinay Maneti Jan 12 '14 at 13:41
0

I suggest you follow the setup carefully at https://developers.google.com/maps/documentation/android/start

From what I see of your manifest, you are missing

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

and

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>

and in the recommended layout is fragment instead of MapView etc..

Daniel Wong
  • 147
  • 2
  • 10
0

You are trying to get map in AVD right, so you can refer this link for how to get map in emulator.

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138