Cannot move map in webview

随声附和 提交于 2019-12-31 05:25:13

问题


One activity (MainActivity) calls a fragment(MainPage). The fragment is designed to open a local asset webview file, Map.html. It works as intended, with the exception that the map cannot be moved by fingertip. This function is available when the Map.html is opened a broswer. However, the zoom in zoom out tap button in the top left does work.

Is something overlaying the webview such that it can be seen but not swiped?

The initial AppCompatActivity (to support ActionBar) is given by MainActivity:

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    //list of private declarations

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    // a lot of other stuff relating to navigation drawer

    // calls MainPage Fragment
    android.support.v4.app.Fragment fragment = new MainPage();
                FragmentManager fragmentManager = getSupportFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.content_frame, fragment)
                        .addToBackStack("tag")
                        .commit();
    }
}

where the xml for this is given as:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_centerVertical="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <WebView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/content_frame">
    </WebView>

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#111">
        </ListView>

    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

Eventually calls MainPage, given as:

public class MainPage extends android.support.v4.app.Fragment implements GeolocationPermissions.Callback {

    public MainPage() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_main, container, false);
        WebView webview = (WebView) rootView.findViewById(R.id.content_frame);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webview.getSettings().setGeolocationEnabled(true);
        GeoClient geo = new GeoClient();
        webview.setWebChromeClient(geo);
        String origin = "";
        geo.onGeolocationPermissionsShowPrompt(origin, this);
        webview.loadUrl("file:///android_asset/Map.html");
        return rootView;
    }

回答1:


You may need to set an onclicklistener. For Google Maps, this is how I did it. Its probably similar.

Add the implements, @override function, and set the onclick listener. I'm not sure if this will work since you are using HTML at some point.

public class MainActivity extends FragmentActivity implements View.OnClickListener,
        GoogleMap.OnMapClickListener {

Then when you initiate it set the onmap click listener.

    gMap.setOnMapClickListener(this);// add the listener for click on gmap object

Finally, add this @override:

@Override
public void onMapClick(LatLng point) {
//What code if any happens when user clicks on map
}


来源:https://stackoverflow.com/questions/42216005/cannot-move-map-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!