Question

I have created an android app based on this: https://code.google.com/p/android-my-map-location/downloads/list that uses google maps. so i have downloaded the project and done everything and added my API key, but when i run the app the map isn't visible, i can only see the zoom buttons and some square tiles.

i know its a problem with my API key but i can't get it right, here is how i get it:

1) from eclipse >> window >> preferences >> android >> build then i find my SHA1 fingerprint. 2) i go to the google API COnsole and make sure i chose the google maps for android v2 is selected. 3) create new android key and pasete my SHA1 fingerprint and my package name.

Can anyone please help me with this this is a direct download link for my project: https://android-my-map-location.googlecode.com/files/android-my-map-location.zip

Was it helpful?

Solution 4

i managed to make it work by following the exact steps in google's developers website:

https://developers.google.com/maps/documentation/android/

OTHER TIPS

You should add this to your manifest

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

External storage for caching

<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"/>

Maps API needs OpenGL ES 2.0.

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

paste this inside application:

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

This can go anywhere in your layout.

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

This should be your MyMapLocationActivity.java

public class MyMapLocationActivity extends FragmentActivity {
    private MapView mMapView;
    private GoogleMap mMap;

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

        mMapView = (MapView) findViewById(R.id.map);
        mMapView.onCreate(savedInstanceState);

        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();

        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        if (mMap == null) {
            mMap = ((MapView) findViewById(R.id.map)).getMap();
            if (mMap != null) {
                setUpMap();
            }
        }
    }

    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }

    @Override
    protected void onPause() {
        mMapView.onPause();
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        mMapView.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mMapView.onLowMemory();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mMapView.onSaveInstanceState(outState);
    }
}

This is a google-play-services sample

Try from your google developer console to authoruze all applications to use your key (leave the field blank).

Create a simple app and check if your API key is correct.

Just create a layout using MapFragment and set it to an activity

activity_map.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"/>

set the layout to activity

   setContentView(R.layout.activity_map);

also add meta tag in manifest under application

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

When you launch your app , you should see map loaded in activity. If this doesn't work issue with your API Key. If works change your code to use a custom MapFragment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top