3

我的模拟器中出现空白屏幕,并且地图没有显示。

这是假设在浏览器中显示的内容:[ http://code.google.com/apis/maps/documentation/javascript/examples/layer-georss.html]

这是清单文件的代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.apps.mylocations"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MyLocations"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>

这是我的布局 XML 文件,它有一个webview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <WebView android:id="@+id/web_engine"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"/>

</LinearLayout>

这是Java代码:

 package com.apps.mylocations;

        import android.app.Activity;
        import android.os.Bundle;
        import android.webkit.WebView;

        public class MyLocations extends Activity {
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);


                WebView engine = (WebView) findViewById(R.id.web_engine);

                engine.getSettings().setJavaScriptEnabled(true);

                String data = "<html>" + 
        "<head>" + 
        "<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\" />" + 
        "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>" + 
        "<title>Google Maps JavaScript API v3 Example: KmlLayer GeoRSS</title>" + 
        "<link href=\"http://code.google.com/apis/maps/documentation/javascript/examples/default.css\" rel=\"stylesheet\" type=\"text/css\" />" + 
        "<script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=false\"></script>" + 
        "<script type=\"text/javascript\">" + 
        "function initialize() {" +
          "var myLatlng = new google.maps.LatLng(49.496675,-102.65625);" +
          "var myOptions = {" +
            "zoom: 4," +
            "center: myLatlng," +
            "mapTypeId: google.maps.MapTypeId.ROADMAP" +
          "}" +

          "var map = new google.maps.Map(document.getElementById(\"map_canvas\"), myOptions);" +

          "var georssLayer = new google.maps.KmlLayer('http://api.flickr.com/services/feeds/geo/?g=322338@N20&lang=en-us&format=feed-georss');" +
          "georssLayer.setMap(map);" +
        "}" +
        "</script>" + 
        "</head>" + 
        "<body onload=\"initialize()\">" + 
          "<div id=\"map_canvas\"></div>" + 
        "</body>" + 
        "</html>";


           engine.loadData(data, "text/html", "UTF-8");


            }
        }
4

3 回答 3

3

您是否已按照现有问题的提示进行操作?

发布android应用程序后谷歌地图不显示?

有谁知道为什么我的地图只显示网格

  • 清单中给出的互联网许可?
  • 地图键正确吗?
于 2010-11-26T08:11:54.880 回答
1

你的代码:

engine.loadData(...)

不允许加载网络资源。因此,由于 HTML 片段试图从网络加载大量资源,所以它根本不起作用。它可以显示的内容是有限的。检查文档:http: //developer.android.com/reference/android/webkit/WebView.html

也许 loadDataWithBaseURL 会更好用?我不确定。我尝试加载您的代码,它使用了很多远程 javascript,从静态/本地 HTML 字符串加载时可能会出现问题。

编辑 12.05.2010:

如果您可以访问某处的服务器(简单),您应该只发布 HTML 并在 webview 上使用 loadUrl 方法。确切的说明来自 Google 自己,以及 Maps API 文档,在这里:

http://code.google.com/apis/maps/articles/android_v3.html http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/

标记

于 2010-11-29T07:23:11.043 回答
1

您是否在需要代理才能访问 Internet 的网络中?如果是,您需要为模拟器设置代理。

http://developer.android.com/guide/developing/tools/emulator.html#proxy

于 2010-11-30T22:21:34.837 回答