Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 谷歌地图api v3和UIWebView iOS内存问题_Iphone_Ios_Google Maps Api 3 - Fatal编程技术网

Iphone 谷歌地图api v3和UIWebView iOS内存问题

Iphone 谷歌地图api v3和UIWebView iOS内存问题,iphone,ios,google-maps-api-3,Iphone,Ios,Google Maps Api 3,在我的iOS应用程序中,我想显示由google maps而不是MKMapView提供的交通信息。因此我使用google maps api v3,但在UIWebView中加载google maps api v3地图会导致内存泄漏。特别是当我们缩放地图并单击卫星按钮时。 代码-- html{高度:100%} 正文{高度:100%;边距:0;填充:0} #地图画布{高度:100%;} #路由_表{高度:0%;} var directionsDisplay=new google.maps.Direct

在我的iOS应用程序中,我想显示由google maps而不是MKMapView提供的交通信息。因此我使用google maps api v3,但在UIWebView中加载google maps api v3地图会导致内存泄漏。特别是当我们缩放地图并单击卫星按钮时。 代码--


html{高度:100%}
正文{高度:100%;边距:0;填充:0}
#地图画布{高度:100%;}
#路由_表{高度:0%;}
var directionsDisplay=new google.maps.DirectionsRenderer();
var directionsService=new google.maps.directionsService();
var arrayInput=[];
var业务层;
var映射;
var标记=[];
var界;
var zoomWidth;
var alertBOOL;
函数初始化(){
var txt=新字符串(%@);
arrayInput=txt.split(',');
//var latlng=new google.maps.latlng(parseFloat(arrayInput[0]),parseFloat(arrayInput[1]);
var latlng=新的google.maps.latlng(-34.397150.644);
变量myOptions={
缩放:5,
中心:拉特林,
disableDefaultUI:true,
街景控制:错误,
背景颜色:“#FFFFF”,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
this.map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
directionsDisplay.setMap(this.map);
directionsDisplay.suppressInfoWindows=true;
addTrafficButton();
添加卫星按钮();
calcRoute(arrayInput);
}
函数计算器(输入阵列){
var i=0;
var-wps=[];
var启动;
var端;
var i=0;
var j=0;

对于(i=0;i我认为你的问题可以通过在ios 5中使用ARC来解决。这是苹果在ios 5中添加的最佳功能。它在你的应用程序中保留了整个内存管理。使用ARC可以帮到你很多。

你的应用程序仍然存在问题。那么你能告诉我你目前面临的问题,以便我可以为它提供适当的解决方案吗。如果你的图像太大然后你必须添加缓存策略…这样你的内存就会刷新…可以为我提供适当的详细信息以便我可以帮助你我正在使用google maps api v3,我的代码已经在我的问题中了。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map_canvas { height: 100%;}
  #route_table { height: 0%;}
</style>
<script type="text/javascript"
    src="http://maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">

  var directionsDisplay = new google.maps.DirectionsRenderer();
  var directionsService = new google.maps.DirectionsService();
  var arrayInput = [];
  var trafficLayer;
  var map;
  var markers = [];
  var bounds;
  var zoomWidth;
  var alertBOOL;

  function initialize() {
    var txt = new String(%@);
    arrayInput  = txt.split(',');
    //var latlng = new google.maps.LatLng(parseFloat(arrayInput[0]),parseFloat(arrayInput[1]));
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 5,
        center: latlng,
        disableDefaultUI:true,
        streetViewControl:false,
        backgroundColor: '#FFFFF',
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    this.map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
    directionsDisplay.setMap(this.map);
    directionsDisplay.suppressInfoWindows = true;
    addTrafficButton();
    addSatelliteButton();
    calcRoute(arrayInput);
  }

  function calcRoute(inputArray) {
    var i=0;
    var wps = [];
    var start;
    var end;
    var i = 0;
    var j=0;
    for(i=0;i<arrayInput.length-1;i=i+2)    
    {    

      if(i==0)
      {    
        start = new google.maps.LatLng(parseFloat(arrayInput[i]),arrayInput[i+1]);
        this.map.center = start;
      }
      else if(i==(arrayInput.length-2))
      {
        end = new google.maps.LatLng(parseFloat(arrayInput[i]),arrayInput[i+1]);
      }
      else
      {    
        wps[j] = { location: new google.maps.LatLng(parseFloat(arrayInput[i]),arrayInput[i+1]) };
        j++;
      }

    }
    bounds = new google.maps.LatLngBounds(start,end);
    this.map.fitBounds(bounds);
    var request =
    {
      origin:start,
      destination:end,
      waypoints: wps,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(result, status)
    {    
      if (status == google.maps.DirectionsStatus.OK)
      {
        directionsDisplay.setDirections(result);
      }
    });
 }
 function addTrafficButton()
 {
   var tbutton = document.createElement("button");
   tbutton.innerHTML = "Traffic On";
   tbutton.style.position = "absolute";
   tbutton.style.bottom = "50px";
   tbutton.style.right = "15px";
   tbutton.style.zIndex = 10;
   tbutton.style.width = "70px";
   tbutton.style.height = "30px";
   this.map.getDiv().appendChild(tbutton);
   tbutton.className = "lolight";
   tbutton.onclick = function() {
     if (tbutton.className == "hilight") {
       tbutton.innerHTML = "Traffic On";
       this.trafficLayer.setMap(null);
       this.trafficLayer = null;
       tbutton.className = "lolight";
     } else {
       tbutton.innerHTML = "Traffic Off";
       this.trafficLayer = new google.maps.TrafficLayer();
       this.trafficLayer.setMap(this.map);
       tbutton.className = "hilight";
     }
   }
 }

function addSatelliteButton()
{
  var sbutton = document.createElement("button");
  sbutton.innerHTML = "Satellite";
  sbutton.style.position = "absolute";
  sbutton.style.bottom = "90px";
  sbutton.style.right = "15px";
  sbutton.style.zIndex = 10;
  sbutton.style.width = "70px";
  sbutton.style.height = "30px";
  this.map.getDiv().appendChild(sbutton);
  sbutton.className = "lolight";
  sbutton.onclick = function() {
    if (sbutton.className == "hilight") {
      sbutton.innerHTML = "Satellite";
      map.setMapTypeId(google.maps.MapTypeId.ROADMAP);    
      sbutton.className = "lolight";
    } else {
      sbutton.innerHTML = "Map";
      sbutton.className = "hilight";
      map.setMapTypeId(google.maps.MapTypeId.HYBRID);
    }
  }
}

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%;"></div>
</body>
</html>