MapKit JS - 为标记添加注释

问题描述 投票:0回答:0

我是第一次使用 Apple 的 MapKit JS,并创建了一个以地理编码为中心的简单地图:

    const main = async() => {
    await setupMapKitJs();

    const marker = new mapkit.CoordinateRegion(
        new mapkit.Coordinate(-33.7332208,151.1296024),
        new mapkit.CoordinateSpan(0.05, 0.05) // latitude delta, longitude delta
    );

    // Create a map in the element whose ID is "map-container"
    const map = new mapkit.Map("map-container");
    map.region = marker;
};

main();

目前正在运行。我现在想在地理编码中添加一个自定义图标,但不能让它与上面的代码一起使用。我找到了另一个看起来像这样的例子:

    const main = async() => {
    await setupMapKitJs();

    // Create the Map and Geocoder
    const map = new mapkit.Map("map-container");

    // Create the "Marker" annotation, setting properties in the constructor.
    const event = new mapkit.Coordinate(-33.7332208,151.1296024);
    const eventAnnotation = new mapkit.MarkerAnnotation(event, {
        color: "#4eabe9",
        title: "Hospital",
        glyphText: "\u{1F37F}" //
    });

    // Add and show both annotations on the map
    map.showItems([eventAnnotation]);


};

main();

但似乎无法将注释代码合并到我的第一个示例中(反之亦然)。无论我尝试什么,我总是在控制台中收到错误消息。

javascript mapkit mapkit-js
© www.soinside.com 2019 - 2024. All rights reserved.