开发者

Whats the issue with the android emulator to display map in Web View

I am getting a blank white screen in my emulator and the map is not getting displayed.

Here is what is suppose to be displayed in a browser: [http://code.google.com/apis/maps/documentation/javascript/examples/layer-georss.html]

Here's the code for manifest file:

<?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>

Here is my layout XML File which has a 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>

Here is Java Code:

 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");


            }
        }


You have followed the hints on existing questions?

google map not showing after publishing android application?

Does anyone know why my maps only show grid

  • internet permission given in manifest?
  • maps key correct?


Are you in a network that need proxy to access Internet? If yes you need to set proxy for emulator.

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


Your code:

engine.loadData(...)

does not allow for loading of network resources. Therefore, since the HTML snippet attempts to load a lot of resources from the network, it won't work at all. It is limited in what it can display. Check the docs: http://developer.android.com/reference/android/webkit/WebView.html

Maybe the loadDataWithBaseURL will work better? I don't know for sure. I tried loading your code, and it uses a lot of remote javascript, which may be a problem when loaded from a static/local HTML string.

EDIT 12.05.2010:

If you have access to a server somewhere (easy), you should just publish the HTML and use the loadUrl method on the webview. The exact instructions come from Google themselves, with the Maps API documentation, here:

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

Mark

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜