google map showing blank in genymotion

£可爱£侵袭症+ 提交于 2019-12-13 04:37:56

问题


I am using Google Nexus 4.2.2 - with Google API on Genymotion. The google maps fragment is coming up empty. I have registered with the API and providing the key in the manifest file. Thanks for your help.

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsTestActivity" >

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

</RelativeLayout>

Activity:

package com.chaseit.activities;

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

import com.chaseit.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsTestActivity extends Activity {

    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;

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

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        setupMap();
        super.onResume();
    }

    private void setupMap() {

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

        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
                .title("Hamburg"));
        Marker kiel = map.addMarker(new MarkerOptions()
                .position(KIEL)
                .title("Kiel")
                .snippet("Kiel is cool")
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.ic_launcher)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.maps_test, menu);
        return true;
    }

}

I got the example code from http://www.vogella.com/articles/AndroidGoogleMaps/article.html


回答1:


Inorder to use google maps v2 in our android application, one must use google-play-services library. This Library works only if context is passed to check whether services is available to that devices. Add this line in your oncreate

GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

Comment me about the result




回答2:


Check the output log, search on maps, and see if warnings notices come up. In my case, I found:

09:03:34.197 E/Google Maps Android API( 7012): Authorization failure.  Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.
03-22 09:03:34.198 E/Google Maps Android API( 7012): In the Google Developer Console (https://console.developers.google.com)
03-22 09:03:34.198 E/Google Maps Android API( 7012): Ensure that the "Google Maps Android API v2" is enabled.
03-22 09:03:34.198 E/Google Maps Android API( 7012): Ensure that the following Android Key exists:

Double check on the following:

  • That you gave the correct SHA1 fingerprint of your application in google developer console (For me, somehow this changed)
  • That you gave the correct package name
  • That you included they API key in the manifest file (Obvious, yes, I know)
  • That the proper permissions are also set in manifest ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION ACCESS_LOCATION_EXTRA_COMMANDS ACCESS_MOCK_LOCATION

  • If using an emulator, insure that Google Play Services (including Maps) is installed.

More detailed directions can be found here.




回答3:


In my case , I did not find a solution,the map is blank when it is opened and navigating the map does nothing , but I had a PlaceAutocompleteFragment and when i use it to search for a place I move the map to that place and it works , the map is now shown and you can navigate it . you don't have to use PlaceAutocompleteFragment you can just get around the problem by moving the camera to a place you want when the map loads and then navigate from there , this can be done by adding this to the onMapReady() function :

LatLng latLng = new LatLng(15.501501,32.4325101) ;// change to the value you want
float zoom = 15.0f;
mapfragment.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));


来源:https://stackoverflow.com/questions/18907071/google-map-showing-blank-in-genymotion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!