【问题标题】:How do you get location data through HTML5 embedded in an Android app?如何通过嵌入在 Android 应用程序中的 HTML5 获取位置数据?
【发布时间】:2013-05-08 05:36:01
【问题描述】:

我正在开发一个 Android 应用程序,基本上,不同的网页嵌入在片段中,并使用列表片段在页面之间切换。我可以通过浏览器获取 HTML5 位置数据,但当页面嵌入到应用程序中时则不行。

忘记片段,我能够并且我可以让 JavaScript 在 WebView 中工作。但即使使用 WebViewClient,我也无法弄清楚如何让地理位置数据正常工作。有人能指出我正确的方向吗?

【问题讨论】:

    标签: android html webview geolocation android-fragments


    【解决方案1】:

    您必须首先在您的WebView 中启用 Javascript 和 GeoLocation

    WebView mWebView;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mWebView = (WebView) findViewById(R.id.webView1);
        // Brower niceties -- pinch / zoom, follow links in place
        mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.setWebViewClient(new GeoWebViewClient());
        // Below required for geolocation
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setGeolocationEnabled(true);
        mWebView.setWebChromeClient(new GeoWebChromeClient());
    
    }
    

    然后你可以使用导航器获取位置数据..

    function getLocation() {
     navigator.geolocation.getCurrentPosition(displayLocation, handleError);
    }
    

    看看这个Post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-26
      • 2013-09-20
      • 1970-01-01
      • 2011-01-31
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      相关资源
      最近更新 更多