I'm developing a simple app for study Android purposes. The app queries a SQLite database using Country, City and Airport names as filters and get the ICAO code of it. So the app queries a webservice (for example http://avdata.geekpilot.net/airport/SBSP.xml ) to get latitude & longitude coordinates of the airport.
So I'm trying to show a Google map of the lat/lon i've got, but everything I see is a screen full of tiles.
I generated the authentication key at https://code.google.com/apis . I get the SHA1 key from debug.keystore file from Eclipse using keytool command. I put the key on manifest and on the Mapview section at screen layout xml file but I cant be successful. The logcat always shows sequential warnings containing messages like:
02-23 10:46:48.856: W/System.err(6359): IOException processing: 26
02-23 10:46:48.856: W/System.err(6359): java.io.IOException: Server returned: 3
02-23 10:46:48.856: W/System.err(6359): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
02-23 10:46:48.856: W/System.err(6359): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
02-23 10:46:48.856: W/System.err(6359): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
02-23 10:46:48.856: W/System.err(6359): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
02-23 10:46:48.856: W/System.err(6359): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
I saw in a tutorial that I should use MD5 key, but when I use it, Google show me a message informing that the key is invalid. I only can get the authentication key when I use SHA1.
I'm referencing google-play-services_lib.jar and maps.jar on my project and haven't checked them on Java Build Path's Order and Export tab.
My class
public class ShowMapActivity extends MapActivity {
private MapView map;
private Double latitude = 0.0;
private Double longitude = 0.0;
private MyLocationOverlay me = null;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
Intent mapCall = getIntent();
latitude = (Double) mapCall.getDoubleExtra(
TestDatabaseActivity.LATITUDE, 0);
longitude = (Double) mapCall.getDoubleExtra(
TestDatabaseActivity.LATITUDE, 0);
map = (MapView) findViewById(R.id.mMap);
final MapController mapController = map.getController();
mapController.setCenter(getPoint(latitude,longitude));
map.setBuiltInZoomControls(true);
Drawable marker=getResources().getDrawable(R.drawable.pushpin_red);
marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
map.getOverlays().add(new SitesOverlay(marker));
me = new MyLocationOverlay(this, map);
map.getOverlays().add(me);
}
private GeoPoint getPoint(double lat, double lon) {
return(new GeoPoint((int)lat, (int)lon));
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> items=new ArrayList<OverlayItem>();
public SitesOverlay(Drawable marker) {
super(boundCenterBottom(marker));
populate();
}
@Override
protected OverlayItem createItem(int i) {
return(items.get(i));
}
@Override
protected boolean onTap(int i) {
Toast.makeText(ShowMapActivity.this,
items.get(i).getSnippet(),
Toast.LENGTH_SHORT).show();
return(true);
}
@Override
public int size() {
return(items.size());
}
}
}
ActivityMap (layout screen)
<?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/mMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:apiKey="my api key here"
android:clickable="true" />
</RelativeLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cinquini.airportlocation"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<permission
android:name="com.cinquini.airportlocation.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<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-feature android:glEsVersion="2" android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.cinquini.airportlocation.TestDatabaseActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.cinquini.airportlocation.ShowMapActivity"
android:label="@string/title_activity_map" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key here"/>
</application>
</manifest>
Is there something that I can't see or is missing on my code?
Once regenerate api key with package name mentioned in manifest and don't forget uninstall the previous app before running the application .
And make sure following steps done correct or not:
Steps: * to ensure that device has Google Play services APK * to install Google Play Service rev. more than 2
android.library.reference.1=google-play-services_lib
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
Okay, now you ready to create your own Google Map app with using Google Map APIs V2 for Android.
If you create application with min SDK = 8, please use android support library v4 + SupportMapFragment instead of MapFragment.
After got this let me know.
Regarding the map issue, please note that we have to use SHA1 fingerprint from the debug.keystore file from our systems. Using this and the package name of the application we can generate map key. You also can use the below tag in Application part of the AndroidManifest.xml to see the map: (if you are using map V2). Also make sure you have turned on Google Android Map V2 in the developer console.
I hope this helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.