Iphone 如何在xcode 6中使用mapKit在点之间绘制线

Iphone 如何在xcode 6中使用mapKit在点之间绘制线,iphone,ios8,Iphone,Ios8,我是iOS开发新手,现在使用的是XCode 6 我想在地图上的两个位置之间画一条路线,就像导游一样。当游客点击另一个位置时,我希望能够画出一条路线;此外,请告知距离当前位置的距离。据我所知,您的问题是您希望在两个位置之间绘制路线。 要实现这一点,首先创建两个UIExField以获取源和目标,并创建一个UIButton以执行操作。 连接所有插座 不要忘记添加地图框架 ViewController.h 我有一个问题:您希望实现哪个流程?1 MKMapKit Direction API。2用于绘制路径

我是iOS开发新手,现在使用的是XCode 6


我想在地图上的两个位置之间画一条路线,就像导游一样。当游客点击另一个位置时,我希望能够画出一条路线;此外,请告知距离当前位置的距离。

据我所知,您的问题是您希望在两个位置之间绘制路线。 要实现这一点,首先创建两个UIExField以获取源和目标,并创建一个UIButton以执行操作。 连接所有插座

不要忘记添加地图框架

ViewController.h


我有一个问题:您希望实现哪个流程?1 MKMapKit Direction API。2用于绘制路径的Google Route API。用于绘制路径的Google Route API。您是否能够绘制路径或需要帮助。我这样问是因为你的分数被接受了。如果你需要帮助,请告诉我。是的,我会画路线图。这段代码对我很有帮助。
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>


@interface ViewController : UIViewController<MKMapViewDelegate>
 {

 IBOutlet UITextField *source1;
 IBOutlet UITextField *destination1;
 IBOutlet MKMapView *map;
 MKAnnotationView *Annotation;

 }
-(CLLocationCoordinate2D)FindCoordinates:(NSString *)place;
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay;
-(IBAction)getLocation:(id)sender;

 @end
#import "ViewController.h"


@interface ViewController ()

{
  CLLocationCoordinate2D myLocation;
  CLLocationCoordinate2D sourceLocation;
  CLLocationCoordinate2D destinationLocation;
}
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

}


-(CLLocationCoordinate2D)FindCoordinates:(NSString *)place
{

NSString *addresss = place;
NSString *esc_addr = [addresss stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString *req = [NSString stringWithFormat: @"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:req]];


NSDictionary  *googleResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSDictionary *resultsDict = [googleResponse valueForKey:  @"results"];   // get the results dictionary
NSDictionary *geometryDict = [   resultsDict valueForKey: @"geometry"];   // geometry dictionary within the  results dictionary
NSDictionary *locationDict = [  geometryDict valueForKey: @"location"];   // location dictionary within the geometry dictionary

// nslo (@”– returning latitude & longitude from google –”);

NSArray *latArray = [locationDict valueForKey: @"lat"]; NSString *latString = [latArray lastObject];     // (one element) array entries provided by the json parser
NSArray *lngArray = [locationDict valueForKey: @"lng"]; NSString *lngString = [lngArray lastObject];     // (one element) array entries provided by the json parser

myLocation.latitude = [latString doubleValue];     // the json parser uses NSArrays which don’t support “doubleValue”
myLocation.longitude = [lngString doubleValue];

return myLocation;

}

-(IBAction)getLocation:(id)sender
{
sourceLocation = [self FindCoordinates:source1.text];
NSLog(@"%@",[NSString stringWithFormat:@"Source lat:%f Source lon:%f",sourceLocation.latitude,sourceLocation.longitude]);
destinationLocation = [self FindCoordinates:destination1.text];
NSLog(@"%@",[NSString stringWithFormat:@"Desti lat:%f Desti lon:%f",destinationLocation.latitude,destinationLocation.longitude]);

CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:sourceLocation.latitude longitude:sourceLocation.longitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:destinationLocation.latitude longitude:destinationLocation.longitude];
CLLocationDistance distance = [loc1 distanceFromLocation:loc2];
NSLog(@"%@",[NSString stringWithFormat:@"Distance iin KMeteres %f",distance/1000]); // Gives me air distance


}


@end