如何在iphone模拟器地图中移动?动态纬度&;在iphone模拟器中获取但不定位经度?

如何在iphone模拟器地图中移动?动态纬度&;在iphone模拟器中获取但不定位经度?,iphone,mkmapview,ios-simulator,Iphone,Mkmapview,Ios Simulator,我从上面的代码获取位置 -(CLLocationCoordinate2D)getGeoCoding:(NSString *)address { NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@",address]; NSURL *url = [NSURL URLWithString:req]; NSError

我从上面的代码获取位置

-(CLLocationCoordinate2D)getGeoCoding:(NSString *)address
{

NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@",address];
NSURL *url = [NSURL URLWithString:req];

NSError *error;
//NSURLResponse *response;
CLLocationCoordinate2D findlocation;
NSData *data = [[NSData alloc]initWithContentsOfURL:url];
NSMutableDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:Nil error:&error];

if(error)
{
    NSLog(@"%@",[error localizedDescription]);
    findlocation.latitude=0.0;
    findlocation.longitude =0.0;
}
else
{
    NSArray *results = (NSArray *)responseDictionary[@"results"];
    NSDictionary *firstitem = (NSDictionary *)[results objectAtIndex:0];
    NSLog(@"%@",firstitem);
    NSDictionary *geometry = (NSDictionary *)[firstitem valueForKey:@"geometry"];
    NSLog(@"%@",geometry);
    NSDictionary *location = (NSDictionary *)[geometry valueForKey:@"location"];
    NSLog(@"%@",location);
    NSNumber *lat = (NSNumber *)[location valueForKey:@"lat"];
    NSLog(@"%@",lat);
    NSNumber *lng = (NSNumber *)[location valueForKey:@"lng"];
    NSLog(@"%@",lng);
    findlocation.latitude = [lat doubleValue];
    findlocation.longitude = [lng doubleValue];

}
return findlocation;
}
在上述函数之后获取位置代码。 函数被调用,但在iPhone模拟器中不起作用。。? 如果设置了任何设置,请告诉我代码中的问题是什么,因为iPhone模拟器地图不会从当前位置移动。。
可能吗?怎么做?

你的问题不清楚。您的意思是
getGeoCoding
返回有效的
位置
,但是
setRegion
不会将地图移动到该坐标吗?将以下NSLog置于setRegion行上方:
NSLog(@“位置=%f,%f;self.mapView=%@”、location.latitude、location.longitude、self.mapView)。当你运行应用程序时,NSLog会说什么?如果mapView显示为nil,请确保IBOutlet已连接。谢谢。通过您的支持,我正在解决一个错误@安娜
  -(void)getLocation:(id)sender
  {
NSString *str = self.textView.text;


CLLocationCoordinate2D location;
location=[self getGeoCoding:str];

self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate=self;

self.mapView.showsUserLocation =YES;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location, 0.3*METERS_PER_MILES, 0.3*METERS_PER_MILES);
[self.locationManager startUpdatingLocation];
[self.mapView reloadInputViews];
[self.mapView setRegion:viewRegion animated:YES];
 }