zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    mysql存儲過程+游標的應用實例5/17
    mysql存儲過程+遊標應用之:找缺號5/19
    轉:愚公移山
    c++中的头文件
    栈和堆:生存空间
    java中的类加载
    c++中的连接
    访问static变量和方法
    子类调用构造函数的过程
    c++中变量的存储种类
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175646.html
Copyright © 2011-2022 走看看