2013年6月6日 星期四

[IOS]使用WebView載入Google地圖

if (DEVICE_IS_IPHONE5)
{
 width = 320;
 height = 504
}
else {
  width = 320;
  height = 460
}

//不包含狀態列
CGRect fullScreenRect = [[UIScreen mainScreen] applicationFrame]; if(fullScreenRect.origin.y == 20)
{
 width = fullScreenRect.size.width;
 height = fullScreenRect.size.height;
}
else{
 height = fullScreenRect.size.width;
 width = fullScreenRect.size.height;
}

NSString *htmlString = [NSString stringWithFormat:@"<html>\ <head>\ <meta id=\"viewport\" name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;\">\ <script src='http://maps.google.com/maps/api/js?sensor=false' type='text/javascript'></script>\ </head>\ <body onload=\"new google.maps.StreetViewPanorama(document.getElementById('p'),{position:new google.maps.LatLng(%f, %f),pov: {heading: 270,pitch:0,zoom:1}});\" style='padding:0px;margin:0px;'>\ <div id='p' style='height:%f;width:%f;'></div>\ </body>\ </html>",lat, lon , height , width];

[webView loadHTMLString:htmlString baseURL:nil];

沒有留言:

張貼留言