支付宝小程序map地图
发布日期:2021-05-20 06:05:14 浏览次数:17 分类:精选文章

本文共 2222 字,大约阅读时间需要 7 分钟。

prosperous journey of map usage in the alipay mini-program.

Polyline Route Configuration

Polyline routes are configured within the data section with the following structure:

polyline: [ { points: [ { latitude: 40.038540, longitude: 116.272389 }, { latitude: 40.041407, longitude: 116.274738 } ], color: "#003355", width: 5, dottedLine: false } ]

Ensure the initial latitude and longitude used for rendering fall within the polyline's range to avoid the route from appearing inactive.

Marker Configuration

Markers are implemented through the markers array:

markers: [ { id: 1, latitude: '', longitude: '', width: 30, height: 50, iconPath: "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=862691749,1690286630&fm=26&gp=0.jpg" }, { id: 2, latitude: '', longitude: '', width: 19, height: 31, iconPath: "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2609580352,4233204507&fm=26&gp=0.jpg" }, { id: 3, latitude: '', longitude: '', width: 19, height: 31, iconPath: "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3064920752,1494594665&fm=26&gp=0.jpg", callout: { content: "报警位置" } } ]

Ensure that the iconPath is correctly set as an absolute path within the project directory, using the format "/pages/image/test.jpg". If using relative paths, please prepend the absolute path to avoid image loading failures. Switching to URL-based paths has proven effective in resolving this issue.

map initialization methods

To activate the map, use the following methods:

my.chooseLocation() - Opens the map to allow users to select a location.

When the location selection is complete, the method returns the following properties:

  • name: Position name
  • address: Detailed address
  • latitude: Latitude (range: -90~90, negative values indicate southern latitudes)
  • longitude: Longitude (range: -180~180, negative values indicate western longitudes)

my.openLocation() - Opens the built-in map (default mobile OS map app) or third-party applications like Gaode.

Code Example for my.openLocation():

my.openLocation({ longitude: this.data.longitude, latitude: this.data.latitude, name: this.data.name, address: this.data.address })

Remember to test the map preview within the app in a real device for optimal performance.

上一篇:svg如何使用
下一篇:微信小程序去除默认导航

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月27日 21时05分30秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章