我已经通过坐标获取了位置名称。
使用此代码
reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
此处 newLocation 包含我当前的位置
而reverseGeocoder是MKReverseGeocoder的类型。
我还添加了 MapKit 框架并添加了委托(delegate) MKReverseGeocoderDelegate。
并在.m文件中定义此委托(delegate)
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{...}
当我们启动此委托(delegate)并使用 (MKPlacemark*)placemark 获取位置时,我会在上述委托(delegate)方法或任何其他用户定义的方法中的 AlertView 中显示此位置,例如:
[[[[UIAlertView alloc] initWithTitle:@"Place"
message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease]
delegate:self
cancelButtonTitle:@"Okay"
otherButtonTitles:nil] autorelease] show];
问题是我的警报 View 每秒都会一次又一次出现。
所以请让我知道如何停止反向地理编码器或如何才能看到此警报 View 一次。
提前致谢。
最佳答案
这个问题是创建的,因为你每次都有新的位置,这个问题可以从两种方式删除...... 1)使用两个位置之间的距离条件...当您的距离大于特定距离时,您会看到警报 View ...
2)如果用户想查看一次警报,则使用此代码...
int count = 0;
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
.......
if(count == 0)
{
[[[[UIAlertView alloc] initWithTitle:@"Place"
message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease]
delegate:self
cancelButtonTitle:@"Okay"
otherButtonTitles:nil] autorelease] show];
count ++;
}
}
3)概念
NSString *previousloaction;///像全局变量一样使用... NSString *currentloaction;///像全局变量一样使用...
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
currentloaction=placemark;
.......
if(![previousloaction isEqucaltoString: currentloaction])
{
[[[[UIAlertView alloc] initWithTitle:@"Place"
message:[[[NSString alloc] initWithFormat:@"%@",placemark] autorelease]
delegate:self
cancelButtonTitle:@"Okay"
otherButtonTitles:nil] autorelease] show];
previousloaction =currentloaction;
}
}
关于iphone - 从坐标中获取位置名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9207101/