周四. 2 月 6th, 2025

marker uni,Understanding the Uni-Marker in Uni-App Development

Understanding the Uni-Marker in Uni-App Development

When delving into the realm of cross-platform development with Uni-App, one of the most crucial elements you’ll encounter is the marker, often referred to as the “uni-marker.” This feature allows you to place interactive elements on a map, making it an essential tool for applications that require location-based functionalities. Let’s explore the ins and outs of the uni-marker, ensuring you have a comprehensive understanding of its capabilities and how to effectively utilize it in your projects.

What is a Uni-Marker?

A uni-marker is a visual element that you can place on a map within a Uni-App project. It is typically used to indicate a specific location, such as a user’s current position or a point of interest. Markers can be customized with icons, labels, and other properties to make them visually distinct and informative.

Creating a Uni-Marker

Creating a uni-marker is a straightforward process. You can define a marker within your Vue component using the `

` element. Here’s an example of how you might set up a basic marker:

<template>  <map style="width: 100%; height: 240px;" :latitude="params.lat" :longitude="params.lon" :markers="covers" /></template><script lang="ts" setup>// 鍦板浘鏍囪鐐归厤缃甛nconst covers = reactive([  {    id: 1,    iconPath: '../../static/image/map-store-red.svg',    latitude: 0,    longitude: 0,    width: 24,    height: 32  },  {    id: 2,    iconPath: '../../static/image/map-owner-blue.svg',    latitude: 0,    longitude: 0,    width: 24,    height: 32  }]);</script>

In this example, we have defined two markers with unique icons and positions. The `iconPath` property specifies the path to the icon image, while the `latitude` and `longitude` properties define the marker’s location on the map.

Customizing Uni-Markers

Uni-Markers offer a variety of customization options to help you create visually appealing and informative maps. Here are some of the key properties you can use to customize your markers:

Property Description
iconPath The path to the icon image used for the marker.
latitude The latitude coordinate of the marker’s location.
longitude The longitude coordinate of the marker’s location.
width The width of the marker’s icon.
height The height of the marker’s icon.
label A label that appears when the marker is clicked.
anchor The anchor point of the marker’s icon, relative to its center.

By utilizing these properties, you can create markers that are not only visually appealing but also informative and interactive.

Handling Marker Events

Uni-Markers can also be used to trigger events when they are interacted with. For example, you can define a click event to display additional information or perform a specific action. Here’s an example of how you might handle a marker click event:

<template>  <map style="width: 100%; height: 240px;" :latitude="params.lat" :longitude="params.lon" :markers="covers" @markertap="handleMarkerTap" /></template><script lang="ts" setup>// 鍦板浘鏍囪鐐归厤缃甛nconst covers = reactive([  // ... (same as before)]);// 澶勭悊鏍囪鐐瑰嚮浜嬩欢function handleMarkerTap(e) {  console.log('Marker tapped:', e.markerId);  // 鍦ㄦ澶勬墽琛岀浉鍏虫搷浣淺n}</script>

In this example,

By google

Related Post