2012-03-23 61 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文件夾。