我已经获得了我的 API 密钥并设置了所有权限。我还设置它使用谷歌地图库,但是当我加载地图布局时我仍然得到灰色网格。我也无法让模拟器使用坐标。它说“禁用的提供商网络”,但是当我在手机上调试时坐标工作得很好。
这是我的布局文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0inWE-rpNsby-evq_ORv1bdMuhprR3R38VeZaAw"
/>
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
这是相应的Java文件。
package com.example.zip.code;
import android.app.Activity;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.google.android.maps.MapView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
public class OpenMap extends MapActivity {
private MapController mapController;
private LocationManager locationManager;
private String prov;
double lat;
double lng;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maplayout);
//Criteria crit = new Criteria();
//prov = locationManager.getBestProvider(crit, false);
//Location loc = locationManager.getLastKnownLocation(prov);
// Get Mapping Controllers etc
MapView mapView = (MapView) findViewById(R.id.map_view);
mapController = mapView.getController();
// Center on Current Position
//mapController.setCenter(new GeoPoint((int) (loc.getLatitude() * 1E6),
// (int) (loc.getLongitude() * 1E6)));
// mapController.setCenter(new GeoPoint(1924000,-99120000));
mapController.setZoom(11);
mapView.setBuiltInZoomControls(true);
}
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mapsettings, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.zipswap:
swapToZip();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void swapToZip(){
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
}
}
我不知道似乎出了什么问题。我已经使用了所有应该需要的东西,但我仍然得到一个灰色的网格。我需要一个单独的密钥来进行调试吗?