1

我对编码很陌生,所以我正在尝试使用 api v3 重新创建谷歌地图的教程。当我运行本教程时,我收到一个空点错误,这似乎是(来自日志猫)由于 setupWebView(); 行

我在 .xml 中定义了 webview 并赋予了适当的权限。这是 WebMapActivity 类 -

public class WebMapActivity extends Activity implements LocationListener {

private static final String MAP_URL = "http://gmaps-samples.googlecode.com/svn/trunk/articles-    android-webmap/simple-android-map.html";
private WebView webView;
private Location mostRecentLocation;

@Override
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getLocation();
setupWebView();
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
/** Sets up the WebView object and loads the URL of the page **/
private void setupWebView(){
final String centerURL = "javascript:centerAt(" +
mostRecentLocation.getLatitude() + "," +
mostRecentLocation.getLongitude()+ ")";
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
//Wait for the page to load then send the location information
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(MAP_URL);
}





/** The Location Manager manages location providers. This code searches
    for the best provider of data (GPS, WiFi/cell phone tower lookup,
    some other mechanism) and finds the last known location.
 **/
private void getLocation() {      
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String provider = locationManager.getBestProvider(criteria,true);

//In order to make sure the device is getting location, request updates.        
locationManager.requestLocationUpdates(provider, 1, 0, this);
mostRecentLocation = locationManager.getLastKnownLocation(provider);
}

/** Sets the mostRecentLocation object to the current location of the device **/
@Override
public void onLocationChanged(Location location) {
mostRecentLocation = location;
}

/** The following methods are only necessary because WebMapActivity implements   
LocationListener    
**/ 
@Override
public void onProviderDisabled(String provider) {
}

@Override
public void onProviderEnabled(String provider) {
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}

}

这是 .xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:id="@+id/webview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"/>
</LinearLayout>

我希望,当然,你能帮上忙。如果需要更多信息,请告诉我...

谢谢,杰米

4

0 回答 0