滚动Googlemaps会导致混乱并且无法顺利运行

时间:2017-02-14 12:36:16

标签: ios google-maps smooth-scrolling

我在iPhone应用中使用谷歌地图。当我用单指滚动地图时,它不会平滑滚动并导致混乱。实际上,每当我滚动地图时,它都会获取地址并显示在地图顶部的textField中。 但是当我滚动太快时,它就不会顺畅滚动。
请任何帮助,我有这个问题大约2天。

提前致谢...!

这是我在地图顶部的文本字段上更新地址的代码。

code

NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=false",[strForLatitude floatValue], [strForLongitude floatValue], [strForLatitude floatValue], [strForLongitude floatValue]];

NSString *str = [NSString stringWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error:nil];

NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding:NSUTF8StringEncoding]
                                                     options: NSJSONReadingMutableContainers
                                                       error: nil];

NSDictionary *getRoutes = [JSON valueForKey:@"routes"];
NSDictionary *getLegs = [getRoutes valueForKey:@"legs"];
NSArray *getAddress = [getLegs valueForKey:@"end_address"];
if (getAddress.count!=0)
{
    NSArray* str = [getAddress objectAtIndex:0];
    if(str.count > 0){
        NSString* address = [[getAddress objectAtIndex:0]objectAtIndex:0];
        //fix crash...
        if(![address isKindOfClass:[NSNull class]]){
            if ([[[getAddress objectAtIndex:0]objectAtIndex:0] isEqualToString:@"338, Nigeria"]) {
                   self.txtAddress.text=@"";
            }
            else
                self.txtAddress.text=[[getAddress objectAtIndex:0]objectAtIndex:0];
        }
    }
}

0 个答案:

没有答案