iphone web显示google地图

来源:互联网 发布:东华软件员工数量 编辑:程序博客网 时间:2024/06/01 09:50

iphone web显示google地图

在含有地图导航功能的 App 中显示乘车信息的话,可以通过 UIView 中显示 Google Map 信息的方法实现


    实现的方法很简单:

    首先创建一个view-base工程,声明UIView变量:

    #import <UIKit/UIKit.h>

    @interface iphone_mpaViewController : UIViewController {

        IBOutlet UIWebView *myWenView;
    }
    @property (nonatomic,retain) UIWebView *myWenView;
    @end

    具体实现如下:

    #import "iphone_mpaViewController.h"

    @implementation iphone_mpaViewController
    @synthesize myWenView;
    - (void)viewDidLoad {
        [super viewDidLoad];
        //获取路线
         NSMutableString *googleSearch = [NSMutableString stringWithFormat:@"http://ditu.google.cn/maps?f=d&source=s_d&saddr='北京'&daddr=31.186371,121.489885&hl=zh&t=m&dirflg=h"];
        [myWenView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[googleSearch stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
    }
    - (void)viewDidUnload {
        self.myWenView=nil;
    }
    - (void)dealloc {
        [super dealloc];
        [self.myWenView release];
    }

    @end



打开xxxcontrol.xib拖一个webview到view上。点击files owner。按下command+2.

按住

myWenView右边的圆圈,拖动到uiwebview上。


按住 new refrencing outlets 


右边的圆圈,拖动到uiwebview上。选delete

然后运行

    通过上面的 URL 可以进行查询。其中 URL 参数的介绍可以查看 Google 地图 http 参数一文。

    在开发中遇到一点问题,就是用地理位置设置成中文时,不能得到相应的地图,最后的解决方案是,把 URL 进行 utf8 encod,上面红色字体部分,把项目设置成中文即可。

    源代码:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.mpa/


原创粉丝点击