0

放大我得到了同樣的問題在下面這樣描述的問題:谷歌地圖 - 讓專線跟隨街道地圖時,在

(路由行不繼街頭,當我放大)

MapKit - Make route line follow streets when map zoomed in

Route drawing on Google Maps for iOS not following the street lines

,但似乎沒有哪個SOLV任何回答編輯提到的問題。

我通過下面的函數加入指向我的GMSMapView中圖:

-(void) addPointToMap:(CLLocationCoordinate2D) coordinate 
{ 
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
                   coordinate.latitude, 
                   coordinate.longitude); 
    GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
    marker.map = mapView_; 
    [waypoints_ addObject:marker]; 
    NSString *positionString = [[NSString alloc] initWithFormat:@"%f,%f", 
           coordinate.latitude,coordinate.longitude]; 
    [waypointStrings_ addObject:positionString]; 
    if([waypoints_ count]>1){ 
     NSString *sensor = @"false"; 
     NSArray *parameters = [NSArray arrayWithObjects:sensor, waypointStrings_, 
           nil]; 
     NSArray *keys = [NSArray arrayWithObjects:@"sensor", @"waypoints", nil]; 
     NSDictionary *query = [NSDictionary dictionaryWithObjects:parameters 
                  forKeys:keys]; 
     MDDirectionService *mds=[[MDDirectionService alloc] init]; 
     SEL selector = @selector(addDirections:); 
     [mds setDirectionsQuery:query 
        withSelector:selector 
        withDelegate:self]; 
    } 

} 

,這裏是setDirectionsQuery功能:

static NSString *kMDDirectionsURL = @"http://maps.googleapis.com/maps/api/directions/json?"; 

- (void)setDirectionsQuery:(NSDictionary *)query withSelector:(SEL)selector 
       withDelegate:(id)delegate{ 
    NSArray *waypoints = [query objectForKey:@"waypoints"]; 
    NSString *origin = [waypoints objectAtIndex:0]; 
    int waypointCount = [waypoints count]; 
    int destinationPos = waypointCount -1; 
    NSString *destination = [waypoints objectAtIndex:destinationPos]; 
    NSString *sensor = [query objectForKey:@"sensor"]; 
    NSMutableString *url = 
    [NSMutableString stringWithFormat:@"%@&origin=%@&destination=%@&sensor=%@", 
    kMDDirectionsURL,origin,destination, sensor]; 
    if(waypointCount>2) { 
    [url appendString:@"&waypoints=optimize:true"]; 
    int wpCount = waypointCount-2; 
    for(int i=1;i<wpCount;i++){ 
     [url appendString: @"|"]; 
     [url appendString:[waypoints objectAtIndex:i]]; 
    } 
    } 
    url = [url 
      stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]; 
    _directionsURL = [NSURL URLWithString:url]; 
    [self retrieveDirections:selector withDelegate:delegate]; 
} 

注:我已經遵​​循了這一谷歌教程,並修改了它一點點:

https://www.youtube.com/watch?v=AdV7bCWuDYg

預先感謝,任何幫助將不勝感激!

回答

0

最後我找到了解決方案,感謝WWJD在他的問題中的最後編輯!

Route drawing on Google Maps for iOS not following the street lines

從答案:

我基本上沒的是,我正在只有用我收到的路由信息​​工作時,如果你檢查你的JSON文件之前從Google路線API接收信息時,您會看到您會收到更多信息。這是我們需要產生正確結果和正確折線的信息。