Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在谷歌地图上画线_Iphone_Iphone Sdk 3.0_Ios4 - Fatal编程技术网

Iphone 如何在谷歌地图上画线

Iphone 如何在谷歌地图上画线,iphone,iphone-sdk-3.0,ios4,Iphone,Iphone Sdk 3.0,Ios4,我想在谷歌地图上画线,线可以是直线,也可以是曲线,但我想画线,让它们连接两个点,可能在任何地理位置 谢谢 GuruPrasad R Gujjar。如果我没记错的话,你需要使用JavaScript,谷歌地图API-键是免费的。 这里的其他一切: 请参阅此项并单击此处。这可能会对您有所帮助。以下是示例代码,请尝试使用此代码。 编辑:您还必须下载“RegexKitLite”头文件和类文件 // This method will calculate the routes and return an a

我想在谷歌地图上画线,线可以是直线,也可以是曲线,但我想画线,让它们连接两个点,可能在任何地理位置

谢谢


GuruPrasad R Gujjar。

如果我没记错的话,你需要使用JavaScript,谷歌地图API-键是免费的。 这里的其他一切:

请参阅此项并单击此处。这可能会对您有所帮助。

以下是示例代码,请尝试使用此代码。 编辑:您还必须下载“RegexKitLite”头文件和类文件


// This method will calculate the routes and return an array with point
-(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: (CLLocationCoordinate2D) t {
    NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, f.longitude];
    NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, t.longitude];

    NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
    NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
    NSLog(@"api url: %@", apiUrl);
    NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl];
    NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"([^\\\"]*)\\\"" capture:1L];

    return [self decodePolyLine:[encodedPoints mutableCopy]];
}
-(NSMutableArray *)decodePolyLine: (NSMutableString *)encoded {
    [encoded replaceOccurrencesOfString:@"\\\\" withString:@"\\"
                                options:NSLiteralSearch
                                  range:NSMakeRange(0, [encoded length])];
    NSInteger len = [encoded length];
    NSInteger index = 0;
    NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
    NSInteger lat=0;
    NSInteger lng=0;
    while (index = 0x20);
        NSInteger dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
        lat += dlat;
        shift = 0;
        result = 0;
        do {
            b = [encoded characterAtIndex:index++] - 63;
            result |= (b & 0x1f) = 0x20);
        NSInteger dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
        lng += dlng;
        NSNumber *latitude = [[[NSNumber alloc] initWithFloat:lat * 1e-5] autorelease];
        NSNumber *longitude = [[[NSNumber alloc] initWithFloat:lng * 1e-5] autorelease];
        printf("[%f,", [latitude doubleValue]);
        printf("%f]", [longitude doubleValue]);
        CLLocation *loc = [[[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]] autorelease];
        [array addObject:loc];
    }

    return array;
}

// This method will draw the route with array of points.
-(void) updateRouteView 
{
    CGContextRef context =  CGBitmapContextCreate(nil, 
                                                  routeView.frame.size.width, 
                                                  routeView.frame.size.height, 
                                                  8, 
                                                  4 * routeView.frame.size.width,
                                                  CGColorSpaceCreateDeviceRGB(),
                                                  kCGImageAlphaPremultipliedLast);

    CGContextSetStrokeColorWithColor(context, lineColor.CGColor);
    CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
    CGContextSetLineWidth(context, 3.0);

    for(int i = 0; i &ls; routes.count; i++) {
        CLLocation* location = [routes objectAtIndex:i];
        CGPoint point = [map convertCoordinate:location.coordinate toPointToView:routeView];

        if(i == 0) {
            CGContextMoveToPoint(context, point.x, routeView.frame.size.height - point.y);
        } else {
            CGContextAddLineToPoint(context, point.x, routeView.frame.size.height - point.y);
        }
    }

    CGContextStrokePath(context);

    CGImageRef image = CGBitmapContextCreateImage(context);
    UIImage* img = [UIImage imageWithCGImage:image];

    routeView.image = img;
    //[self.view addSubview:routeView];
    CGContextRelease(context);

    //29-07-10
    CGContextRef context2 =     CGBitmapContextCreate(nil, 
                                                  routeView2.frame.size.width, 
                                                  routeView2.frame.size.height, 
                                                  8, 
                                                  4 * routeView2.frame.size.width,
                                                  CGColorSpaceCreateDeviceRGB(),
                                                  kCGImageAlphaPremultipliedLast);

    CGContextSetStrokeColorWithColor(context2, lineColor2.CGColor);
    CGContextSetRGBFillColor(context2, 0.0, 0.0, 1.0, 1.0);
    CGContextSetLineWidth(context2, 3.0);

    for(int i = 0; i &ls; routes2.count; i++) {
        CLLocation* location2 = [routes2 objectAtIndex:i];
        CGPoint point2 = [map convertCoordinate:location2.coordinate toPointToView:routeView2];

        if(i == 0) {
            CGContextMoveToPoint(context2, point2.x, routeView2.frame.size.height - point2.y);
        } else {
            CGContextAddLineToPoint(context2, point2.x, routeView2.frame.size.height - point2.y);
        }
    }

    CGContextStrokePath(context2);

    CGImageRef image2 = CGBitmapContextCreateImage(context2);
    UIImage* img2 = [UIImage imageWithCGImage:image2];

    routeView2.image = img2;
    //[self.view addSubview:routeView];
    CGContextRelease(context2);

}
我认为这将有助于你完成任务