2

我正在尝试使用 PhoneGap 工具集构建应用程序,并希望使用 mapbox 显示地图。我正在用 html、js 和 css 开发它,并使用 PhoneGap 桌面服务器工具在 android 设备上对其进行测试。

我已经通过 config.xml 文件成功集成了插件

<plugin name="cordova-plugin-mapbox" spec="1.2.3"> <variable name="ACCESS_TOKEN" value="[secret access token here]" /> </plugin>

而且我试图在这里参考插件的文档,但是我看不到如何使用这个插件在 div 中实际生成 mapbox 地图?

目前我已经尝试在设备就绪调用中复制他们的演示代码:

`

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    Mapbox.show(
      {
        style: 'emerald', // light|dark|emerald|satellite|streets , default 'streets'
        margins: {
          left: 0, // default 0
          right: 0, // default 0
          top: 316, // default 0
          bottom: 50 // default 0
        },
        center: { // optional, without a default
          lat: 52.3702160,
          lng: 4.8951680
        },
        zoomLevel: 12, // 0 (the entire world) to 20, default 10
        showUserLocation: true, // your app will ask permission to the user, default false
        hideAttribution: false, // default false, Mapbox requires this default if you're on a free plan
        hideLogo: false, // default false, Mapbox requires this default if you're on a free plan
        hideCompass: false, // default false
        disableRotation: false, // default false
        disableScroll: false, // default false
        disableZoom: false, // default false
        disablePitch: false, // disable the two-finger perspective gesture, default false
        markers: [
          {
            lat: 52.3732160,
            lng: 4.8941680,
            title: 'Nice location',
            subtitle: 'Really really nice location'
          }
        ]
      },

      // optional success callback
      function(msg) {
        console.log("Success :) " + JSON.stringify(msg));
      },
      // optional error callback
      function(msg) {
        alert("Error :( " + JSON.stringify(msg));
      }
    )};

`

但通常(在浏览器/网络应用程序中)我希望看到一个新的地图框对象被创建并与绘制地图的 div 相关联,但我不知道如何使用这个插件来做到这一点。

4

0 回答 0