无法在WebView中移动地图 [英] Cannot move map in webview
问题描述
一个活动(MainActivity)调用一个片段(MainPage).该片段旨在打开本地资产Webview文件Map.html.它可以按预期工作,但不能用指尖移动地图.在浏览器中打开Map.html时,此功能可用.但是,左上方的放大缩小点击按钮确实起作用.
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.
是否在Web视图上覆盖了一些东西,以便可以看到但不能滑动?
Is something overlaying the webview such that it can be seen but not swiped?
最初的AppCompatActivity(以支持ActionBar)由MainActivity给出:
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();
}
}
其中的xml表示为:
<?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>
最终调用MainPage,如下所示:
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;
}
推荐答案
您可能需要设置onclicklistener.对于Google地图,这就是我的做法.可能差不多.
You may need to set an onclicklistener. For Google Maps, this is how I did it. Its probably similar.
添加工具@override函数,并设置onclick侦听器.我不确定这是否行得通,因为您有时正在使用HTML.
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 {
然后在启动它时设置onmap点击监听器.
Then when you initiate it set the onmap click listener.
gMap.setOnMapClickListener(this);// add the listener for click on gmap object
最后,添加此@override:
Finally, add this @override:
@Override
public void onMapClick(LatLng point) {
//What code if any happens when user clicks on map
}
这篇关于无法在WebView中移动地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!