热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在Mapkit的其他位置用蓝色圆点显示用户的位置?-Howtoshowuser'slocationwithbluedotinotherplaceofMapkit?

Imanewcomerofswift3&Xcode8,andthisismyfirsttimetoaskquestionhere.Iwanttos

I'm a newcomer of swift 3 & Xcode 8, and this is my first time to ask question here. I want to set several pins in a Mapkit, and I also want to add user's location in the same Mapkit simultaneously. Furthermore, I hoped that the center of this Mapkit is a specific location instead of user's location. However, I faced a problem.

我是swift 3 & Xcode 8的新手,这是我第一次在这里提问。我想在Mapkit中设置几个大头针,同时还想在同一个Mapkit中添加用户的位置。此外,我希望这个Mapkit的中心是一个特定的位置而不是用户的位置。然而,我遇到了一个问题。

I could set those pins in my Mapkit successfully, but I could not show user's location in the same Mapkit. If I try to set user's location as the center of this Mapkit, I could show user's location successfully. My codes was shown below.

我可以在Mapkit中成功设置这些大头针,但是我不能在相同的Mapkit中显示用户的位置。如果我试图设置用户的位置作为这个Mapkit的中心,我可以成功地显示用户的位置。我的代码如下所示。

import UIKit
import MapKit
import CoreLocation

class MapVC: UIViewController, CLLocationManagerDelegate {

@IBOutlet weak var MapView: MKMapView!

let manager = CLLocationManager()

func createSpanAndAnnotation() {
    let FirstSpan: MKCoordinateSpan = MKCoordinateSpanMake(0.008, 0.008)
    let originalLocation:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 24.942653, longitude: 121.368598)
    let EdittedRegion:MKCoordinateRegion = MKCoordinateRegion(center: originalLocation, span: FirstSpan)
    MapView.setRegion(EdittedRegion, animated: true)

    let TemporaryGarbageCanLatitude = showData().garbageCanLatitudeArray
    let TemporaryGarbageCanLOngtitude= showData().garbageCanLontitudeArray
    let TemporaryGarbageCanDiscription = showData().garbageCanDiscription
// 'showdata' is another class to store my data of garbageCans in another file.

    for i in 0...TemporaryGarbageCanLatitude.count-1 {
    let garbageCanLocation : CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: TemporaryGarbageCanLatitude[i], longitude: TemporaryGarbageCanLongtitude[i])
    let pin = PinAnnotation(title: "Free Garbage Can", subtitle: TemporaryGarbageCanDiscription[i], coordinate: garbageCanLocation)
    MapView.addAnnotation(pin)
    }   
}

//--------------------------------------------------------------------------
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    self.MapView.showsUserLocation = true
}

func locationManager2() {
    manager.delegate = self
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.requestWhenInUseAuthorization()
    manager.startUpdatingLocation()
}
//----------------------------------------------------------------

override func viewDidLoad() {
    super.viewDidLoad()
    createSpanAndAnnotation()
    locationManager2()  
 }
}

I have added 'CoreLocation.framework' in Build Phases, and I also have added 'Privacy - Location When In Use Usage Description' in info.plist file. I also turned on the location services in setting when I ran the simulator. Additionally, I didn't live in USA, so I even went to 'simulator > Debug > Location > Custom location' to change my location to where I stay now.

我在构建阶段添加了“coreloc.org .framework”,我还在info中添加了“在使用使用描述时的隐私位置”。plist文件。在运行模拟器时,我还打开了设置中的位置服务。另外,我没有住在美国,所以我甚至去了“模拟器>调试>位置>自定义位置”,将我的位置更改为我现在停留的位置。

However, I still couldn't not show user's location successfully after I finished all of the things above. Could anyone help me to solve this problem? I would appreciate it if anyone could help me, thanks!

然而,在我完成以上所有的事情之后,我仍然无法成功地显示用户的位置。谁能帮我解决这个问题吗?如果有人能帮我,我将不胜感激,谢谢!

(My screen shot of my Mapkit is here, but I blurred some confidential information on it.) simulator screen shot

(我的Mapkit屏幕截图在这里,但我模糊了其中的一些机密信息)模拟器屏幕截图

1 个解决方案

#1


1  

I found that I solved my problem unexpectedly by changing my custom location in simulator. I lived in east hemisphere, so it seems that the longitude of the place I stayed is positive. However, I typed my longitude as negative value originally. When I changed my longitude to a positive value, my location was shown on the Mapkit successfully.

我发现我通过在模拟器中改变我的自定义位置意外地解决了我的问题。我住在东半球,所以我住的地方的经度似乎是正的。然而,我最初将经度输入为负值。当我将经度更改为正值时,我的位置成功地显示在Mapkit上。

Thanks for every genius who helped me to solve my problem.

谢谢每一个帮助我解决问题的天才。


推荐阅读
  • IOS开发之短信发送与拨打电话的方法详解
    本文详细介绍了在IOS开发中实现短信发送和拨打电话的两种方式,一种是使用系统底层发送,虽然无法自定义短信内容和返回原应用,但是简单方便;另一种是使用第三方框架发送,需要导入MessageUI头文件,并遵守MFMessageComposeViewControllerDelegate协议,可以实现自定义短信内容和返回原应用的功能。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • vue使用
    关键词: ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • 修复安装win10失败并提示“磁盘布局不受UEFI固件支持”的方法
    本文介绍了修复安装win10失败并提示“磁盘布局不受UEFI固件支持”的方法。首先解释了UEFI的概念和作用,然后提供了两种解决方法。第一种方法是在bios界面中将Boot Mode设置为Legacy Support,Boot Priority设置为Legacy First,并关闭UEFI。第二种方法是使用U盘启动盘进入PE系统,运行磁盘分区工具DiskGenius,将硬盘的分区表设置为gpt格式,并留出288MB的内存。最后,通过运行界面输入命令cmd来完成设置。 ... [详细]
author-avatar
I-1ove-Y0u
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有