Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android谷歌地图在网络视图上_Java_Android_Google Maps_Android Maps - Fatal编程技术网

Java android谷歌地图在网络视图上

Java android谷歌地图在网络视图上,java,android,google-maps,android-maps,Java,Android,Google Maps,Android Maps,我有一个jqueryMobile应用程序,它使用谷歌地图api,在iOS上正常工作。然而,我无法在android上运行它。我在清单文件上设置了以下权限。文件已正确加载,但我无法查看地图!假设jqmobile代码可以工作,因为它可以在iOS上工作,那么如何启用它或者需要哪些步骤?多谢各位 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name=

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

<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" />

可能是个愚蠢的回答,但你的清单上有这个吗

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


可能是一个愚蠢的答案,但您的清单中有这个吗

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

您不使用Google有什么特别的原因吗


我知道它使用的是jQuery,但这可能更简单。

您不使用Google有什么特别的原因吗

我知道它使用的是jQuery,但这可能更简单。

好的,试试这个

使用GoogleAPI创建一个新项目,然后试试这个

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();
        }
    }
}
请同时检查。我有同样的问题,现在已经解决了

好的,试试这个

使用GoogleAPI创建一个新项目,然后试试这个

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

请同时检查。我有同样的问题,现在已经解决了

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

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

如何将html文件放入文件目录?也许它在这个过程中被破坏了?尝试删除一个只有一些文本的纯html页面,看看WebView是否以这种方式显示html。html没有错误。再次检查。还使用android和iOS在远程服务器上进行了测试,并且针对iOS works进行了测试。您是如何将html文件放入文件目录的?也许它在这个过程中被破坏了?尝试删除一个只有一些文本的纯html页面,看看WebView是否以这种方式显示html。html没有错误。再次检查。还使用android和iOS从远程服务器进行了测试,并针对iOS works进行了测试。是的,出于某些原因,我需要使用webView。这应该是一项简单的任务。。。确实是在iOS上,但这个问题让我在android上发疯了……最好先运行setJavaScriptEnabled(true),但它可能与jqmobile有关。如果它是特定于iOS的,它是什么?这可能是javascript中的错误,导致页面的其余部分无法正确初始化。该问题的解决方案是什么?我需要移植我的以mapView为中心的android应用程序,以使用加载了google maps的webView,这样我就可以尝试将我的APK重新打包为blackberry BAR。@twig,因为我们不必包括整个androidx库和google maps库,这会减慢生成的Apkye的速度和膨胀,出于某些原因,我需要使用webView。这应该是一项简单的任务。。。确实是在iOS上,但这个问题让我在android上发疯了……最好先运行setJavaScriptEnabled(true),但它可能与jqmobile有关。如果它是特定于iOS的,它是什么?这可能是javascript中的错误,导致页面的其余部分无法正确初始化。该问题的解决方案是什么?我需要移植我的以mapView为中心的android应用程序,以使用加载了google maps的webView,这样我就可以尝试将我的APK重新打包为blackberry BAR。@twig,因为我们不必包括整个androidx库和google maps库,这会减慢构建速度,并且会使生成的apkIt膨胀,这是值得一试的,我知道我以前犯过那个错误值得一试,我知道我以前犯过那个错误