Google Map API v2 is not showing Map on device

后端 未结 6 825
一个人的身影
一个人的身影 2020-12-29 05:42

I am running sample code that is provided on Google Map Documentation for Google Map Api v2 (https://developers.google.com/maps/documentation/android/start#specify_settings_

相关标签:
6条回答
  • 2020-12-29 06:15

    In case anyone else is as dumb as me... make sure the device you are testing on is connected to WiFi...

    0 讨论(0)
  • 2020-12-29 06:20

    To maintain security for the system and users, Android requires apps to request permission before the apps can use certain system data and features. Depending on how sensitive the area is, the system may grant the permission automatically, or it may ask the user to approve the request.

    https://developer.android.com/guide/topics/permissions/index.html

    0 讨论(0)
  • 2020-12-29 06:23

    Use Fragment activity

    eg:

    public class Maps extends FragmentActivity {
        GoogleMap map;
        double lat;
        double lan;
        boolean flag = false;
    
        // private LocationManager lm;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.mapptry);
    
            map = ((SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
                     }
      }
    

    Change ur map.xml to

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

    EDIT

    Got to do this also

    import android.support.v4.app.FragmentActivity;

    Before you do this Right click project->properties->buildpath->java build path -> libraries .. then click on add external jars

    the go to

    user\android-sdks\extras\android\support\v4

    and select android-support-v4.jar

    PS: Do all this provided your API key is correct . If you API key is wrong then also it shows only a white screen

    0 讨论(0)
  • 2020-12-29 06:25

    try to add

    GoogleMap googleMap =    ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
    

    and replace your xml with

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

    you have added the following code outside application tag instead put it inside the tag

    <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
    
    <permission
        android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    

    hope this might help someone who is facing the same problem

    0 讨论(0)
  • 2020-12-29 06:25

    Most probably your problem will be solved when you make sure below mentioned things:

    1. Activate Google Map API

    2. Use correct package name while generating API Key (in my case this was the mistake) .. and this seems problem to your case also as package name appears to be wrong (com.example.mapdemo)

    3. Make Sure you are using the correct keystore file for generating the SHA1

    Hope this will be helpful.

    0 讨论(0)
  • 2020-12-29 06:36

    May be this problem with API key or you just check your SHA1 fingerprint in your project api console(https://console.developers.google.com/project) and your eclipse Windows -> Preferences -> Android -> Build are same, other wise just update the SHA1 from console to build path or vice versa.

    0 讨论(0)
提交回复
热议问题