Android的WebView中加载GoogleMap的数据呈现 [英] Android WebView loading GoogleMap Data Rendering

查看:304
本文介绍了Android的WebView中加载GoogleMap的数据呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用follwoing函数来显示的WebView在div

I'm trying to display the div inside the WebView using the follwoing function

String baseUrl = "";
String mimeType = "text/html";
String encoding = "UTF-8";
html = sb.toString();
String historyUrl = "";

webViewDataViewer.loadDataWithBaseURL(baseUrl, html, mimeType, encoding, historyUrl);

这里是我的html:

here is my html :

 "<html> "+
    " <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />" +
    " <head> <body>  " +
    " <script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=true' ></script> " +
    " <script type='text/javascript'>" +
    " <div id='map_canvas' style='width:100%;height:100%;'></div>" +
    "  var locations = [ ['<h3>A1 A2</h3><img src='assets/user_26/thumb_0.jpg' alt='img' /><p>S, I</p><p>G</p><p>G, 4343, India</p>amit', 28.6392112, 77.3496616], ['<h3>F</h3><img src='' alt='img' /><p>Test</p><p>Test</p><p>Test, 355441, India</p>amit', 19.5851331, -99.0572702]," +
    " ['<h3>B1</h3><img src='' alt='img' /><p>Test</p><p>Test</p><p>Test, 45665, India</p>am', 19.5851331, -99.0572702]," +
    " ['<h3>C1</h3><img src='assets/user_34/thumb_userImage.png' alt='img' /><p>2134 Lawton st</p><p>San Francisco, 94122, United States</p>amit', 37.757809, -122.485946]," +
    " ['<h3>D1</h3><img src='' alt='img' /><p>La</p><p>La</p><p>Abc, 110031, </p>amit', 30.0041868, -90.2159207]," +
    " ['<h3>E1</h3><img src='assets/user_36/thumb_0.jpg' alt='img' /><p>US</p><p>US, 123456, United States</p>amit', 34.797063, -82.294022]," +
    " ['<h3>G1</h3><img src='assets/user_38/thumb_0.jpg' alt='img' /><p>1 Market St</p><p>San Francisco, 94123, United States</p>amit', 37.7944988, -122.3947446]," +
    " ['<h3>T0</h3><img src='' alt='img' /><p>Sfvf</p><p>Fgf</p><p>Fsv, 33133, India</p>amit', 25.7307897, -80.2377078], " +
    " ['<h3>GT7</h3><img src='assets/user_45/thumb_0.jpg' alt='img' /><p>Newyork</p><p>Us</p><p>Hju, 4556, India</p>amit', 40.760118, -73.830034]," +
    " ['<h3>R2</h3><img src='' alt='img' /><p>Asdfhjkkl</p><p>San Fran, 94104, United States</p>amit', 37.7911148, -122.4021273],];" +
    "  var count = 0; "+
    "  var total_lng = 0;  var total_lat = 0; " +" total_lat += 28.6392112;"+
                                           " total_lng += 77.3496616;"+
                                            "count += 1; "+                                
                                           " total_lat += 19.5851331;"+
                                           " total_lng += -99.0572702;"+
                                           " count += 1; " +                             
                                           "total_lat += 19.5851331;"+
                                           "total_lng += -99.0572702;"+
                                           "count += 1;"+                                       
                                           "total_lat += 37.757809;"+
                                           "total_lng += -122.485946;"+
                                           "count += 1;"  +                                    
                                           "total_lat += 30.0041868;"+
                                           "total_lng += -90.2159207;"+
                                          " count += 1;   total_lat += 34.797063;    total_lng += -82.294022;"+ 
                                         "  count += 1;             total_lat += 37.7944988;  total_lng += -122.3947446;   "+
                                          " count += 1; total_lat += 25.7307897;     total_lng += -80.2377078;" +                           
                                           " count += 1; total_lat += 40.760118;    total_lng += -73.830034;"+                             
                                           " count += 1;   total_lat += 37.7911148;  total_lng += -122.4021273;"+                                    
                                           " count += 1;   "+                                     

                           " if(count) {"+
                           "     avg_lat = total_lat / count;"+
                           "     avg_lng = total_lng / count;  "+                          
                           " } else {"+
                           "     avg_lat = 40;"+
                           "     avg_lng = -96;"+
                           " }"+

                        "var mapOptions = "+
                       "{"+
                         "   center: new google.maps.LatLng(avg_lat, avg_lng), "+
                          "  zoom: 4,"+
                        "    scrollwheel: false,"+
                        "    streetViewControl: false,"+

                      "      mapTypeId: google.maps.MapTypeId.ROADMAP,"+
                        "    navigationControlOptions: {"+
                       "         style: google.maps.NavigationControlStyle.SMALL"+

                          "}"+
                        "};"+

                       " var map = new google.maps.Map(document.getElementById('map_canvas'),  mapOptions);"+
                      "  var infowindow = new google.maps.InfoWindow();"+
                      "  var marker, i;"+
                      "  if(locations.length > 0) {"+
                         "   for (i = 0; i < locations.length; i++) "+
                           " {   "+                   
                          "      marker = new google.maps.Marker({"+
                             "       position: new google.maps.LatLng(locations[i][1], locations[i][2]),"+
                              "      map: map"+
                             "   });"+

                               " google.maps.event.addListener(marker, 'click', (function(marker, i) {"+
                                "    return function() {"+
                                   "     infowindow.setContent(locations[i][0]);"+
                                     "   infowindow.open(map, marker);"+
                                    "}"+
                               " })(marker, i));     "+           
                            "}   "+
                        "} </script>    "
           "  </body> </head>  </html>"

这是在Android浏览器,但在Android的WebView中没有数据显示正确的displayed.i'm无法弄清楚什么是错在这里。

this is displaying correctly in Android Browser but in Android WebView no data is displayed.i'm not able to figure out what is wrong here.

推荐答案

尝试这样的:

String html= "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(html, "text/html", null);

科西嘉中,取代HTML例子,我给你的HTML。

Of corse, replace the html example i gave with your html.

这篇关于Android的WebView中加载GoogleMap的数据呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆