谷歌地图api v3教程错误。我究竟做错了什么??

时间:2013-01-27 17:45:49

标签: google-maps null

我非常重视编码,所以我正在尝试使用api v3重新创建Google地图教程。当我运行教程时,由于行setupWebView(),我得到一个零点错误,似乎是(来自log cat);

我在.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>

我希望,当然,你可以提供帮助。 如果需要更多信息,请告诉我......

谢谢, 杰米

0 个答案:

没有答案