2012-03-23 56 views
2

我有一个jqueryMobile应用程序使用谷歌地图API,并在iOS上正常工作。但是,我无法让它在android上运行。我在我的清单文件上设置了以下权限。文件已正确加载,但我无法查看地图!假设jqmobile代码正在工作,因为在iOS上工作,如何启用它或需要哪些步骤?谢谢。android谷歌地图上的webview

<uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> 
    <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" /> 

我的WebView类是什么样子,

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.webview); 

     browse4 = (WebView) findViewById(R.id.webview1); 
     browse4.getSettings().setJavaScriptEnabled(true); 
     browse4.getSettings().setUseWideViewPort(true); 
     browse4.getSettings().setLoadWithOverviewMode(true); 
     browse4.getSettings().setBuiltInZoomControls(true); 
     browse4.getSettings().setSupportZoom(true); 

     browse4.loadUrl("file:///data/data/" + PACKAGE_NAME + "/files/" + "myMap.html"); 

    } 
+0

你如何让你的html文件进入你的文件目录?也许它在这个过程中被破坏了?尝试在一个纯HTML页面上放一些文本,看看WebView是否以这种方式显示你的html。 – FoamyGuy 2012-03-23 20:25:47

+0

html没有错误。再次检查。也从远程服务器使用Android和iOS和iOS工作进行测试。 – Jaume 2012-03-23 20:58:53

回答

1

是否有任何特殊原因导致您未使用Google MapView

我明白这是使用jQuery,但这个可能会更容易。

+0

是的,因为一些原因,我需要使用一个webView应该是一个简单的任务......真的是在iOS上但这个问题让我对Android变得疯狂...... – Jaume 2012-03-24 18:32:10

+0

你最好先setJavaScriptEnabled(true)运行,但它可能与jqmobile有关,如果它是iOS特定的,它是什么?它可能是一个错误javascript,导致页面的其余部分无法正确初始化 – twig 2012-03-25 22:29:51

+0

问题的解决方案是什么?我需要移植我的mapView中心的android应用程序,以使用带有谷歌地图的webView加载到它,以便我可以尝试重新打包我的APK作为黑莓BAR。 – topwik 2013-01-10 20:17:37

0

可能是一个愚蠢的答案,但你有这个在您的清单?

<uses-library android:name="com.google.android.maps" /> 
+0

已经添加到清单:( – Jaume 2012-03-24 15:49:59

+0

这是值得一试,我知道我已经犯了 – testingtester 2012-03-24 19:22:27

0

好的尝试这种

创建使用谷歌API一个新的项目和尝试。

package com.ab1209.webview; 

import android.app.Activity; 
import android.content.Context; 
import android.content.pm.ActivityInfo; 
import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

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; 

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

    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 the location, request 
     // updates. 
     locationManager.requestLocationUpdates(provider, 1, 0, this); 
     mostRecentLocation = locationManager.getLastKnownLocation(provider); 
    } 

    @Override 
    public void onLocationChanged(Location arg0) 
    { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onProviderDisabled(String provider) 
    { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onProviderEnabled(String provider) 
    { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) 
    { 
     // TODO Auto-generated method stub 

    } 

    /** 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); 
     /** Allows JavaScript calls to access application resources **/ 
     webView.addJavascriptInterface(new JavaScriptInterface(), "android"); 
    } 

    /** 
    * Sets up the interface for getting access to Latitude and Longitude data 
    * from device 
    **/ 
    private class JavaScriptInterface 
    { 
     public double getLatitude() 
     { 
      return mostRecentLocation.getLatitude(); 
     } 

     public double getLongitude() 
     { 
      return mostRecentLocation.getLongitude(); 
     } 
    } 
} 

同时请this。我有同样的问题现在解决了。

0

你不能像那样访问文件。您需要将其放入assets文件夹中,然后使用file:///android_asset/file_name.html访问它。如果您具有root访问权限,则只能直接访问/data/data文件夹。