1

当用户根据这个新位置在文本字段中输入新的位置地址时,我需要用谷歌地图刷新 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&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 只是在按下按钮后禁用。

有任何想法吗?

4

2 回答 2

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);
    }

}
}
于 2013-02-27T11:07:52.620 回答
0

试试google.maps.event.trigger(map, 'resize');它对我有用!

于 2015-06-01T20:28:11.640 回答