Zeke Xiao

Zeke Xiao

github

Baidu Maps JS API does not support touch and zoom (Windows tablets, Qt WebEngine).

Reference link: http://blog.sina.com.cn/s/blog_73a4b2cd0102wpgy.html

var myNavigator={};
myNavigator.platform="win32";
myNavigator.userAgent="Mozilla/5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
myNavigator.appVersion="5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";

Then replace Navigator with myNavigator to make Baidu think you are a touch device.

  • Replace the original API with the local API
    <script type="text/javascript" src="http://api.map.baidu.com/api?2.0&ak=xxx"></script>

->

<script type="text/javascript" src="./map.js"></script>


  • If you need to support both mouse and touch

Reference link: https://blog.csdn.net/davis_dxs/article/details/82425211

// TODO: Trigger this event when touch movement occurs, enabling dragging. Although the map is not draggable when initialized, it can trigger the dragging event.
map.addEventListener("touchmove", function (e) {
  map.enableDragging();
});
// TODO: Trigger this event when touch ends, disabling dragging.
map.addEventListener("touchend", function (e) {
  map.disableDragging();
});

// Initialize the map and disable dragging. Note: Although dragging is disabled, it can still trigger the dragging event.
map.disableDragging();

map.enableScrollWheelZoom(true);
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.