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

查看:91
本文介绍了如何通过单击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;

纬度值"和经度值"是文本框
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...!

推荐答案

您可以通过以下代码设置纬度值和经度值:

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是一个结构,所以它没有方法或吸气剂的概念.唯一的正确方法是访问结构成员的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天全站免登陆