2013-02-27 129 views
1

当用户根据此新位置将新位置地址放入文本字​​段时,我需要用Google地图刷新iframe。如何刷新Google地图?

我的HTML代码:

<input type="text" id="address" /> 
<input type="button" id="search" value="Search" onclick="javascript:findLocation();"/> 
<iframe id="mapView" width="700" height="385" 
    frameborder="0" scrolling="no" 
    marginheight="0" marginwidth="0" 
    src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Kharkiv&amp;aq=&amp;vpsrc=0&amp;ie=UTF8&amp;hq=&amp;hnear=Kharkiv&amp;z=14&amp;output=embed"> 
</iframe> 

我的JavaScript代码:

function findLocation(){ 
    var location=document.getElementById('address').value; 
    var newLocation="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q="+location+"&amp;aq=&amp;vpsrc=0&amp;ie=UTF8&amp;hq=&amp;hnear="+location+"&amp;z=14&amp;output=embed"; 
    document.getElementById("mapView").src=newLocation; 
    document.getElementById("mapView").reload(true); 
} 

但按下按钮后IFRAME只是禁用。

任何想法?

回答

1

使用计时器来从舞台中删除的地图,然后重新添加,呼吁全谷歌地图的生命周期:

package 
{ 
import com.google.maps.LatLng; 
import com.google.maps.Map; 
import com.google.maps.MapEvent; 
import com.google.maps.MapType; 

import flash.display.Sprite; 
import flash.events.TimerEvent; 
import flash.geom.Point; 
import flash.utils.Timer; 

public class Test extends Sprite 
{ 

    private var _map:Map; 

    private var _timer:Timer; 

    public function Test() 
    { 
     super(); 

     createMap(); 

     _timer = new Timer(300000); // 5-min 
     _timer.addEventListener(TimerEvent.TIMER, timerHandler); 
     _timer.start(); 
    } 

    private function timerHandler(event:TimerEvent):void 
    { 
     while (numChildren > 0) 
      removeChildAt(0); 

     createMap(); 
    } 

    protected function createMap():void 
    { 
     _map = new Map(); 
     _map.key = "YOUR_API_KEY"; 
     _map.sensor = "false"; 
     _map.setSize(new Point(stage.stageWidth, stage.stageHeight)); 
     addChild(_map); 

     _map.addEventListener(MapEvent.MAP_READY, mapReadyHandler); 
    } 

    protected function mapReadyHandler(event:MapEvent):void 
    { 
     _map.removeEventListener(MapEvent.MAP_READY, mapReadyHandler); 
     _map.setCenter(new LatLng(37.4419, -122.1419), 13, MapType.NORMAL_MAP_TYPE); 
    } 

} 
} 
0

尝试google.maps.event.trigger(map, 'resize');它与我的工作!