【发布时间】:2017-03-15 21:41:06
【问题描述】:
在 viewDidLoad 中,我将当前位置显示在地图中。
CLLocationCoordinate2D coordinate = [self getLocation];
strForCurLatitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
strForCurLongitude= [NSString stringWithFormat:@"%f", coordinate.longitude];
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coor zoom:14];
[mapView_ animateWithCameraUpdate:updatedCamera];
但是在那之后,当我在两个文本字段 textFieldDidEndEditing 中给出两个不同的位置时,我有两个文本字段,然后相机没有移动或更新或更改谷歌地图中该位置的位置,这里我给出了我尝试过的代码但是它没有用。
GMSCameraUpdate *updatedCamera;
if(textField==self.txtAddress)
{
CLLocationCoordinate2D coor;
coor.latitude=[strForLatitude doubleValue];
coor.longitude=[strForLongitude doubleValue];
pref = [NSUserDefaults standardUserDefaults];
[pref setObject:strForLatitude forKey:@"Pickup_Latitude"];
[pref setObject:strForLongitude forKey:@"Pickup_Longitude"];
[pref synchronize];
updatedCamera = [GMSCameraUpdate setTarget:coor zoom:14];
[mapView_ animateWithCameraUpdate:updatedCamera];
}
if(textField==self.txtDropoffAddress)
{
CLLocationCoordinate2D coor;
coor.latitude=[[pref objectForKey:@"Destination_Latitude"] doubleValue];
coor.longitude=[[pref objectForKey:@"Destination_Longitude"] doubleValue];
updatedCamera = [GMSCameraUpdate setTarget:coor zoom:14];
[mapView_ animateWithCameraUpdate:updatedCamera];
}
请帮我解决这个问题..
【问题讨论】:
-
你想做什么??
-
你在这里得到了
pref objectForKey:@"Destination_Latitude"的值 -
如果条件
pref = [NSUserDefaults standardUserDefaults];,您首先为pref 赋值,如果条件[[pref objectForKey:@"Destination_Latitude"] doubleValue];,第二个尝试从中获取值 -
您在哪里以及如何设置键
Destination_Latitude和Destination_Longitude的值? -
@nikdange_me 我编辑并更新了我的问题。
标签: ios objective-c google-maps