Javier Diaz Charles
Javier Diaz Charles

Reputation: 198

Android Google Maps API key?

Ive been messing around with an open source application named "Open GPS Tracker" and I've been having trouble getting google maps to work on it. I have acquired my own API key based off my package name and SHA1 fingerprint, but I cannot get the map to show anything but a grid. The manifest permissions and the map.xml file is below. Any suggestions would be greatly appreciated.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.sogeti.android.gpstracker"
android:installLocation="auto"
android:versionCode="85"
android:versionName="0.5" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="16" />

<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<uses-feature
    android:name="android.hardware.location.gps"
    android:required="true" />

<application
    android:allowClearUserData="true"
    android:description="@string/app_name"
    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <uses-library android:name="com.google.android.maps" />

} MAPS.XML

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mapScreen"
>
<com.google.android.maps.MapView
   android:id="@+id/myMapView"

  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:enabled="true"
  android:clickable="true"
  android:apiKey="my key is here" 
  android:visibility="visible" />
<!--  Release         : 0bmdf4-ggC50QWBY1OgGRutQ9bIboIy11OczZbw -->
<!--  Emulator        : 0bmdf4-ggC50QJGdjml6Turq0NJdMhKFQNdhkYA -->

<org.osmdroid.views.MapView
  android:id="@+id/myOsmMapView"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  renderer="CLOUDMADESTANDARDTILES"
  cloudmadeStyle="1"
  android:visibility="gone"
 />

Upvotes: 0

Views: 5042

Answers (3)

Pihu
Pihu

Reputation: 1039

As Version 1 is deprecated, I suggest to try the Version2 (V2) and moreover it works on the devices having Jelly Bean(4.0 and above). So in order to run on devices lower than 4.0 android support library is required.

Extend your MainActivity with FragmentActivity since fragment has been used in xml layout to display the map..

public class MainActivity extends FragmentActivity implements OnMapClickListener, LocationListener

 private GoogleMap myMap;

   myMap = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map)).getMap();`

Add this in your xml also:

<fragment 
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />

Upvotes: 0

Shailendra Madda
Shailendra Madda

Reputation: 21551

See here,just change the api key with your key in manifest file and follow these steps: and make sure that your google_play_services_lib project should be present in your project's work space only.

Manifest file:

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <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" />
    <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.geeklabs.map.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="replace with your API key"/>

    </application>

</manifest>

MainActivity.java:

    package com.geeklabs.map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

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"
          android:name="com.google.android.gms.maps.MapFragment"/>

After got this let me know.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006819

There are two Maps APIs for Android: Maps V1 and Maps V2.

Maps V1 uses com.google.android.maps.MapView. It does not use SHA1 fingerprints for obtaining an API key, as you cannot get an API key for Maps V1. Maps V1 is deprecated.

Maps V2 does use an API key for which you use an SHA1 fingerprint, where you get the API key via the Google APIs Console. However, that does not use com.google.android.maps.MapView, nor <uses-library android:name="com.google.android.maps" />.

I suggest that you drop all the Maps V1 elements from your app and move over completely to Maps V2.

Upvotes: 1

Related Questions