您的位置:首页 > 其它

调用地图并带有导航功能的两种最简单方式

2013-08-31 10:50 330 查看
第一种方法先自定义一个webview(我用的XIB直接拖一个webview用iboutlet链接)然后

- (void)viewDidLoad
{

[palceWeb
loadRequest:[NSURLRequest
requestWithURL:[NSURL
URLWithString:[NSString
stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
34.755806
,
113.673187
,
[b]35.055806[/b]
,
114.073187
]]]];
}

就可以直接显示路线并支持自驾、公交、步行三种方式的路线查询同时可以实现导航(如果想要实现跳转页面的效果可以作如下操作)

新建一个controller然后调用presentViewController:beemVC方法即可代码如下

    BeemViewController *beemVC=[[BeemViewController alloc]initWithNibName:@"BeemViewController" bundle:nil];

    beemVC.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;

    void(^task)()=^{

        NSLog(@"这个页面是=====%@",self);

    };

    beemVC.homeLat=home.latitude;

    beemVC.homeLon=home.longitude;

    beemVC.officeLat=office.latitude;

    beemVC.officeLon=office.longitude;

     //跳转页面将地图放到webview上显示并适时导航

    [self presentViewController:beemVC animated:YES completion:task];

第二种方法 

摘自网上的调用本机自带的google地图有个弊端(调用地图后无法返回到自己的程序软件下)代码如下

//定义目的地CLLocationCoordinate2D类型

    CLLocationCoordinate2D ofice;
    ofice.latitude =
office.latitude;
    ofice.longitude =
office.longitude;

    //调用google地图定位
   
MKMapItem *currentLocation = [MKMapItem
mapItemForCurrentLocation];

    //调用google地图完成导航

    MKMapItem *toLocation = [[MKMapItem
alloc] initWithPlacemark:[[MKPlacemark
alloc] initWithCoordinate:ofice
addressDictionary:nil]];
    toLocation.name =
@"当前位置";
    [MKMapItem
openMapsWithItems:[NSArray
arrayWithObjects:currentLocation, toLocation,
nil]

     launchOptions:[NSDictionary
dictionaryWithObjects:[NSArray
arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber
numberWithBool:YES],
nil]forKeys:[NSArray
arrayWithObjects:MKLaunchOptionsDirectionsModeKey,
MKLaunchOptionsShowsTrafficKey, nil]]];

-----------------------------------------------------------下面二图为第一种方式的效果图



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: