我不知道我的问题是什么,谷歌地图没有显示
我已将项目属性更改为 Google API 2.3.3,并且没有显示错误
这是我的代码:
映射.java
package com.mapping;
import java.io.IOException;
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
public class Mapping extends MapActivity {
private MapView mapView = null;
private Geocoder geoCoder = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
// latitude and longitude of Dallas, TX
// set as starting point
int lat = (int)(37.422006 * 1000000); //the geocoder requires integers...
int lon = (int)(-122.084095 * 1000000);
//make these into a GeoPoint:
GeoPoint startPoint = new GeoPoint(lat, lon);
mapView.getController().setZoom(12);
mapView.getController().setCenter(startPoint);
geoCoder = new Geocoder(this);
}
public void mapHandler(View v) {
switch(v.getId()) {
case R.id.btnSat:
mapView.setSatellite(true);
break;
case R.id.btnTraf:
mapView.setTraffic(true);
break;
case R.id.btnNorm:
mapView.setSatellite(false);
mapView.setTraffic(false);
break;
}
}
public void geocode(View v) {
EditText geoLocation = (EditText) findViewById(R.id.txtLocation);
if(Geocoder.isPresent()) {
try {
String addr = geoLocation.getText().toString();
List<Address> locationList = geoCoder.getFromLocationName(addr, 5);
if(locationList != null && locationList.size() > 0) {
int lat = (int)(locationList.get(0).getLatitude() * 1000000);
int lon = (int)(locationList.get(0).getLongitude() * 1000000);
GeoPoint setPoint = new GeoPoint(lat, lon);
mapView.getController().setZoom(14);
mapView.getController().setCenter(setPoint);
}
} catch (IOException error) {
Log.i("Caught IOException", "-----Printing Stack Trace-----");
error.printStackTrace();
}
} else {
geoLocation.setText("No Geocoder Available");
}
}
protected boolean isLocationDisplayed() {
return false;
}
protected boolean isRouteDisplayed() {
return false;
}
}
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnSat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Satellite"
android:onClick="mapHandler" />
<Button
android:id="@+id/btnTraf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Traffic"
android:onClick="mapHandler" />
<Button
android:id="@+id/btnNorm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:onClick="mapHandler" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/txtLocation"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:text="Dallas" />
<Button
android:id="@+id/btnGeocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find Location"
android:onClick="geocode" />
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:apiKey="0G_pKeFNWX5lw7PQ7AzKnl2XbRs7bHZ3p6ECosQ" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mapping"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".Mapping" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
谁能帮我?我整天都在拉头发。该程序运行正常,如您所见,我可以截屏,因此它必须是设备与 Google API 的连接。我似乎找不到错误...