简体   繁体   中英

Google maps API v2 not working on device

Currently I am working on Google Maps and for creating that I followed all instructions in the android developers site. But I cant load map in my device, but I can point various places and all. Will my device support Google API V2? Is there any way to view map on my device? My device version is 2.3.3.

I have a working GoogleMaps v2 application and initially I had the same issues that you describe. The problem in my case was that the API key I used was not matching the certificate I used to sign the application (debug/dev for the development phase and release for the Play released app). The application is working on all Android versions from 10 and on (so it works on 2.3.3). From the log error it sssems you may be having a connectivity issue. Did you declare the appropriate uses permissions? It should be:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Here is a short snippet of the main map code:

public class LocationActivity extends MapActivity {


    private MapController mapController;
    private MapView mapView;
    private LocationManager locationManager;
    private MyLocationOverlay myLocationOverlay;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if(Utils.isRelease(getApplicationContext())) {
            setContentView(R.layout.location_activity_release); // bind the layout to the activity
        } else {
            setContentView(R.layout.location_activity); // bind the layout to the activity
        }

        // Configure the Map
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(false);
        mapController = mapView.getController();
        mapController.setZoom(15); // Zoon 1 is world view

        myLocationOverlay = new MyLocationOverlay(this, mapView);
        mapView.getOverlays().add(myLocationOverlay);
        // More map configurations follow...

And the layouts (notice the difference in the maps API key): location_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:apiKey="@string/google_maps_v1_api_key"
    android:clickable="true" /> 

And (location_activity_release.xml):

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:apiKey="@string/google_maps_v1_api_key_release"
    android:clickable="true" /> 

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM