当用户根据这个新位置在文本字段中输入新的位置地址时,我需要使用Google地图刷新iframe。
我的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&source=s_q&hl=en&geocode=&q=Kharkiv&aq=&vpsrc=0&ie=UTF8&hq=&hnear=Kharkiv&z=14&output=embed">
</iframe>
我的JavaScript代码:
function findLocation(){
var location=document.getElementById('address').value;
var newLocation="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q="+location+"&aq=&vpsrc=0&ie=UTF8&hq=&hnear="+location+"&z=14&output=embed";
document.getElementById("mapView").src=newLocation;
document.getElementById("mapView").reload(true);
}
但iframe只是在按下按钮后禁用。
有什么想法吗?
答案 0 :(得分:1)
使用计时器从舞台中删除地图并重新添加,调用完整的Google地图生命周期:
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);
}
}
}
答案 1 :(得分:0)
尝试google.maps.event.trigger(map, 'resize');
它与我合作!