当前位置: 首页 > wzjs >正文

用rp怎么做网站按钮下拉框阿里指数怎么没有了

用rp怎么做网站按钮下拉框,阿里指数怎么没有了,房山建站公司,网络代理软件是什么背景 在使用geoLocationManager的getCurrentLocation方法获得的用户定位经纬度的坐标系为 WGS84 ,但是mapkit使用的是GCJ02坐标系。因此,我们在使用获取用户经纬度然后直接生成标记时,会出现坐标偏移问题。如下: 解决方案 使用…

背景

在使用geoLocationManager的getCurrentLocation方法获得的用户定位经纬度的坐标系为 WGS84 ,但是mapkit使用的是GCJ02坐标系。因此,我们在使用获取用户经纬度然后直接生成标记时,会出现坐标偏移问题。如下:
在这里插入图片描述

解决方案

使用map.convertCoordinateSync方法,对已有的经纬度进行坐标系转换,生成GCJ02坐标系下的经纬度数值。
其中this.LocationLongitude和this.LocationLatitude都是viewmodel类中定义的经纬度。

直接获取经纬度代码

  /*** 更新用户定位*/public async UpdateLocation() {try {const result = await geoLocationManager.getCurrentLocation();this.LocationLongitude = result.longitude;this.LocationLatitude = result.latitude;} catch (err) {console.info("VM", "errCode:" + JSON.stringify(err));}}

获取转换后经纬度代码

public async UpdateLocationByConvert() {try {const result = await geoLocationManager.getCurrentLocation();let wgs84Position: mapCommon.LatLng = {latitude: result.latitude,longitude: result.longitude};let gcj02Position: mapCommon.LatLng =map.convertCoordinateSync(mapCommon.CoordinateType.WGS84, mapCommon.CoordinateType.GCJ02, wgs84Position);this.LocationLongitude = gcj02Position.longitude;this.LocationLatitude = gcj02Position.latitude;} catch (err) {console.info("VM", "errCode:" + JSON.stringify(err));}}

实现效果:
请添加图片描述

完整代码

View

import { MapComponent } from "@kit.MapKit"
import { MapBlogViewModel } from "../ViewModels/MapBlogViewModel"@Entry
@ComponentV2
export struct MapBlogDemo {@Local MapVM: MapBlogViewModel = new MapBlogViewModel()aboutToAppear(): void {}build() {RelativeContainer() {MapComponent({mapOptions: this.MapVM.MapOption,mapCallback: this.MapVM.MapCallBack}).width("100%").height('70%').id("Map")Column({ space: 10 }) {Button("在我的位置创造一个标点").onClick(() => {this.MapVM.CreateLocationMarkerEvent();})Button("在我的位置创造一个转换后的标点").onClick(async () => {await this.MapVM.UpdateLocationByConvert();this.MapVM.CreateLocationMarkerEvent();})}.width("100%").height('30%').alignRules({top: { anchor: "Map", align: VerticalAlign.Bottom },bottom: { anchor: "__container__", align: VerticalAlign.Bottom }})}.height('100%').width('100%')}
}

ViewModel

import { map, mapCommon, sceneMap } from "@kit.MapKit"
import { AsyncCallback } from "@kit.BasicServicesKit"
import { geoLocationManager } from "@kit.LocationKit"
import { common } from "@kit.AbilityKit"
import { trustedAppService } from "@kit.DeviceSecurityKit"@ObservedV2
export class MapBlogViewModel {/*** 地图初始化参数设置*/@Trace MapOption?: mapCommon.MapOptions/*** 地图回调方法*/MapCallBack?: AsyncCallback<map.MapComponentController>/*** 地图控制器*/@Trace MapController?: map.MapComponentController/*** 地图监听管理器*/@Trace MapEventManager?: map.MapEventManager/*** 当前位置的维度*/public LocationLatitude: number = 39.9;/*** 当前位置的经度*/public LocationLongitude: number = 116.4;/*** 缩放数值*/public ZoomNumber: number = 20/*** 定位标记*/@Trace LocationMarker?: map.Markerconstructor() {this.MapOption = {//相机位置position: {target: {latitude: 39.9,longitude: 116.4},zoom: this.ZoomNumber},//地图类型mapType: mapCommon.MapType.STANDARD,//地图最小图层,默认值为2minZoom: 2,//地图最大图层,默认值为20maxZoom: 20,//是否支持旋转手势rotateGesturesEnabled: true,//是否支持滑动手势scrollGesturesEnabled: true,//是否支持缩放手势zoomGesturesEnabled: true,//是否支持倾斜手势tiltGesturesEnabled: true,//是否展示缩放控件zoomControlsEnabled: true,//是否展示定位按钮myLocationControlsEnabled: true,//是否展示指南针控件compassControlsEnabled: true,//是否展示比例尺scaleControlsEnabled: false,//是否一直显示比例尺,只有比例尺启用时该参数才生效。alwaysShowScaleEnabled: false};this.MapCallBack = async (err, mapController) => {if (!err) {this.MapController = mapController;//地图监听时间管理器this.MapEventManager = this.MapController.getEventManager();//启用我的位置图层this.MapController.setMyLocationEnabled(true);this.UpdateLocation().then(() => {});}}this.MoveCamera(this.LocationLatitude, this.LocationLongitude)}/*** 创建我的位置定位标记*/public async CreateLocationMarkerEvent() {let markerKey: string = 'DirectionKey';// Marker初始化参数let markerOptions: mapCommon.MarkerOptions = {position: {latitude: this.LocationLatitude,longitude: this.LocationLongitude},rotation: 0,visible: true,zIndex: 0,alpha: 1,anchorU: 0.5,anchorV: 1,clickable: false,draggable: false,flat: false,icon: "LocationIcon.svg",infoWindowAnchorU: 0,infoWindowAnchorV: 0};if (this.MapController) {// 创建Markerthis.LocationMarker = await this.MapController.addMarker(markerOptions);//设置标记可以拖拽this.LocationMarker.setDraggable(false);// 设置信息窗的标题// this.LocationMarker.setTitle(markerKey);// 设置标记可点击this.LocationMarker.setClickable(false);// 设置信息窗的锚点位置this.LocationMarker.setInfoWindowAnchor(1, 1);this.MoveCamera(this.LocationLatitude, this.LocationLongitude);}}/*** 展示地点选取页,更新标记地点*/public async ShowChoosingLocation() {let locationChoosingOptions: sceneMap.LocationChoosingOptions = {// 地图中心点坐标location: { latitude: this.LocationLatitude, longitude: this.LocationLongitude },language: 'zh_cn',// 展示搜索控件searchEnabled: true,// 展示附近PoishowNearbyPoi: true};// 拉起地点选取页let result: sceneMap.LocationChoosingResult =await sceneMap.chooseLocation(getContext(this) as common.UIAbilityContext, locationChoosingOptions);this.LocationLatitude = result.location.latitude;this.LocationLongitude = result.location.longitude;animateTo({duration: 500}, () => {this.MoveCamera(this.LocationLatitude, this.LocationLongitude);this.UpdateLocationMarker(result.location);})}/*** 更新定位位置* @param latLng*/private UpdateLocationMarker(latLng: mapCommon.LatLng) {if (this.LocationMarker) {this.LocationLatitude = latLng.latitude;this.LocationLongitude = latLng.longitude;this.LocationMarker.setPosition(latLng);}}/*** 更新用户定位*/public async UpdateLocation() {try {const result = await geoLocationManager.getCurrentLocation();this.LocationLongitude = result.longitude;this.LocationLatitude = result.latitude;} catch (err) {console.info("VM", "errCode:" + JSON.stringify(err));}}public async UpdateLocationByConvert() {try {const result = await geoLocationManager.getCurrentLocation();let wgs84Position: mapCommon.LatLng = {latitude: result.latitude,longitude: result.longitude};let gcj02Position: mapCommon.LatLng =map.convertCoordinateSync(mapCommon.CoordinateType.WGS84, mapCommon.CoordinateType.GCJ02, wgs84Position);this.LocationLongitude = gcj02Position.longitude;this.LocationLatitude = gcj02Position.latitude;} catch (err) {console.info("VM", "errCode:" + JSON.stringify(err));}}/*** 移动视图相机* @param latitude 维度* @param longitude 经度*/public async MoveCamera(latitude: number, longitude: number) {if (this.MapController) {//将视图移动到标点位置let nwPosition = map.newCameraPosition({target: {latitude: latitude,longitude: longitude},zoom: 15})// 以动画方式移动地图相机this.MapController.animateCamera(nwPosition, 1000);}}
}

总结

上面地图遇到获取当前位置的经纬度的数值直接用来做标点时候,标点位置不正确的bug

http://www.dtcms.com/wzjs/211099.html

相关文章:

  • ps怎么做电商网站网站收录查询方法
  • 祭祖网站怎么做百度爱采购怎么推广
  • 做网站 信科网络杭州百度快速排名提升
  • 在线网页代理访问安卓优化大师官网
  • 哈铁工程建设公司网站百度关键词查询网站
  • wordpress导航彩条福州专业的seo软件
  • 研究院网站模板网站怎么优化排名的方法
  • 自己做的网站如何连接入数据库西安区seo搜索排名优化
  • 社保个人网站优化关键词步骤
  • 网站菜单分类怎么做的新十条优化措施
  • 成都网站建设易维达好网络工程师是干什么的
  • 无锡网站建设维护微营销推广软件
  • 零基础做网站托管竞价账户哪家好
  • 河北网站设计公司专业的制作网站开发公司
  • 郑州建设信息网打不开厦门谷歌seo公司有哪些
  • 网站做链接算侵权吗网站建设一条龙
  • 重庆公司建设网站新网站推广最直接的方法
  • 网站根目录在哪里中文搜索引擎排名
  • 龙岗 网站建设金华关键词优化平台
  • 青岛网站建站百度网站收录提交入口
  • 点餐网站模板 手机端域名收录查询工具
  • 中国人在俄罗斯做网站需要多少卢布seo引擎优化外包
  • 微信做淘宝客 网站打不开百度开放云平台
  • 服装网页怎么制作搜索引擎优化的方式有哪些
  • 查询网站旗下域名seo教程之关键词是什么
  • 网上建立网站赚钱太原关键词排名优化
  • 怎么做旅游网站推广怎么做百度推广
  • 网站建设seo优化的好处百度热搜榜排名今日
  • 免费网站报价单怎么做长沙seo推广外包
  • 网站建设实训室域名信息查询系统