如何通过单击 iOS 中的特定注释来获取值? [英] How to get the values by clicking specific annotations in iOS?

查看:29
本文介绍了如何通过单击 iOS 中的特定注释来获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个地图视图和 2 个文本框.两个文本框都显示纬度和经度.
我在地图视图中绘制或映射了一些注释,单击每个注释时,标注会显示相应的纬度和经度值.
我只想在我的文本框中显示这些纬度和经度值.我尝试了以下代码,

I am having a map view and 2 text boxes in my app. Both the text boxes display the latitude and longitude.
I have plotted or mapped few annotations in my map view, and when each annotation is clicked, the callout is displayed with the corresponding latitude and longitude value.
I just want to display those latitude and longitude value in my text boxes. I tried the following code,

latitude_value.text=myAnnotation.title;
longitude_value.text=myAnnotation.subtitle;

latitude_value 和 longitude_value 是文本框
myAnnotation 是注解名称
标题和副标题包含纬度和经度值.
提前致谢...!

latitude_value and longitude_value are the text boxes
myAnnotation is the annotation name
title and subtitle contains latitude and longitude values.
Thanks in advance...!

推荐答案

您可以通过以下代码设置 latitude_value 和 longitude_value:

you can set latitude_value and longitude_value by this code:

float latitude = [myAnnotation coordinate].latitude;
float longitude = [myAnnotation coordinate].longitude;
latitude_value.text=[NSString stringWithFormat:@"%f",latitude];
longitude_value.text=[NSString stringWithFormat:@"%f",longitude];

因为 CLLocationCoordinate2D 是一个结构体,所以它没有方法或 getter 的概念.访问结构体成员的 C 点语法是唯一正确的方法.

Because CLLocationCoordinate2D is a struct, so it has no concept of methods or of getters. The C dot syntax for accessing struct members is the only correct method.

这篇关于如何通过单击 iOS 中的特定注释来获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆