Cannot move map in webview(无法在 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.
是否有东西覆盖在 webview 上以便可以看到但不能滑动?
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 给出为:
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>
最终调用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.对于谷歌地图,我就是这样做的.应该差不多吧.
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 中移动地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法在 webview 中移动地图
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01