Javascript 当页面被重新加载时,我如何用现有数据刷新谷歌地图标记和地图?

Javascript 当页面被重新加载时,我如何用现有数据刷新谷歌地图标记和地图?,javascript,cookies,google-maps-api-3,google-maps-markers,google-maps-autocomplete,Javascript,Cookies,Google Maps Api 3,Google Maps Markers,Google Maps Autocomplete,我需要一种方法来刷新和重新加载我的谷歌地图和标记与数据,以前保存。本质上,我希望用户能够自动完成地址,从查询中存储信息的lat、long和place_id,然后如果他们再次返回页面,使用最新的搜索标记和地图图像重新加载地图 $('#jobLoadingAddressLat').val(place.geometry.location.lat()) $('#jobLoadingAddressLng').val(place.geometry.location.lng()) $("#jobLoad

我需要一种方法来刷新和重新加载我的谷歌地图和标记与数据,以前保存。本质上,我希望用户能够自动完成地址,从查询中存储信息的lat、long和place_id,然后如果他们再次返回页面,使用最新的搜索标记和地图图像重新加载地图

 $('#jobLoadingAddressLat').val(place.geometry.location.lat())
 $('#jobLoadingAddressLng').val(place.geometry.location.lng())
 $("#jobLoadingAddressID").val(place.place_id);
这就是我用来解析地图信息的方法。当用户返回页面时,我是否可以使用此信息重新加载地图和标记


将信息存储在cookie中是最佳选择吗?你们推荐什么?提前感谢。

我使用html格式的脚本

        <script>
            var geocoder;
            var map;
            var marker;
            var latLng;

            function codeAddress() {

                // alert("hizo click ....!!!!")
                // We obtain the address and assign it to a variable
                if (document.getElementById("fPersonal:inputDir").value.length > 0) {
                    // alert("Direccion mayor a 0");
                    var combo;
                    var selectValue;
                    var indice;
                    indice = document
                            .getElementById("fPersonal:cComuna_input").selectedIndex;

                    //Validate if combo is selected
                    if (indice == null || indice == 0 || indice == -1) {

                        selectValue = '';
                        alert("Seleccione una Comuna para busqueda : ");

                    } else {
                        combo = document
                                .getElementById('fPersonal:cComuna_input');
                        selectValue = combo.options[combo.selectedIndex].text;

                        var address = document
                                .getElementById("fPersonal:inputDir").value
                                + ", " + selectValue + "," + " Chile";
                        //alert(address);

                        // We create the Geocoder Object
                        var geocoder = new google.maps.Geocoder();
                        // We make the request indicating the address and invoke the function
                        // geocodeResult sending all the result obtained
                        geocoder.geocode({
                            'address' : address
                        }, geocodeResult);
                    }
                }
            }

            function geocodeResult(results, status) {

                if (results.length == 1) {
                    // Verificamos el estatus
                    if (status == 'OK') {

                        // If there are found results, we center and repaint the map                            
                        // this to remove any pin before put
                        var mapOptions = {
                            zoom : 15,
                            center : results[0].geometry.location,
                            mapTypeId : google.maps.MapTypeId.ROADMAP
                        };
                        map = new google.maps.Map(document
                                .getElementById("fPersonal:map"),
                                mapOptions);

                        // I get latitude and longitude in text fields
                        document.getElementById("fPersonal:inputLatitud").value = results[0].geometry.location
                                .lat();
                        document.getElementById("fPersonal:inputLongitud").value = results[0].geometry.location
                                .lng();

                        // fitBounds will zoom in on the map with the right zoom according to what you are looking for
                        map.fitBounds(results[0].geometry.viewport);

                        // We draw a marker with the location of the first result obtained
                        var markerOptions = {
                            position : results[0].geometry.location
                        }
                        marker = new google.maps.Marker(markerOptions);
                        marker.setMap(map);

                        google.maps.event.addListener(map, 'click',
                                function(event) {
                                    //alert(5);
                                    updateMarker(event.latLng);
                                });

                    } else {

                        // If there are no results or an error has occurred
                        // we launched a message with the error
                        //alert("Geocoding no tuvo éxito debido a: " + status);

                        document.getElementById("fPersonal:inputLatitud").value = '';
                        document.getElementById("fPersonal:inputLongitud").value = '';
                        document.getElementById("fPersonal:inputDir").value = '';

                    }
                } else {

                    // If there are no results or an error has occurred
                    // we launched a message with the error
                    // alert ("results is greater than 1:" + results.length);

                    document.getElementById("fPersonal:inputLatitud").value = '';
                    document.getElementById("fPersonal:inputLongitud").value = '';
                    document.getElementById("fPersonal:inputDir").value = '';

                }
            }

            // I update the position on the scoreboard
            function updateMarker(location) {
                marker.setPosition(location);
                updateMarkerPosition(location);

            }
            // I retrieve latitude, longitude and direction to put it in the form
            function updateMarkerPosition(latLng) {

                //alert(latLng.lat());
                document.getElementById("fPersonal:inputLatitud").value = latLng
                        .lat();
                document.getElementById("fPersonal:inputLongitud").value = latLng
                        .lng();
            }
        </script>

var地理编码器;
var映射;
var标记;
var latLng;
函数代码地址(){
//警报(“hizo点击…!!”)
//我们获取地址并将其分配给一个变量
if(document.getElementById(“fPersonal:inputDir”).value.length>0){
//警报(“指示市长a 0”);
var组合;
var选择值;
印度变种;
索引=文件
.getElementById(“fPersonal:ccumuna_input”)。选择索引;
//验证是否选择了组合
if(indice==null | | indice==0 | | indice==1){
选择值=“”;
警报(“Seleccione una Comuna para busqueda:”);
}否则{
combo=文档
.getElementById('fPersonal:ccumuna_input');
selectValue=combo.options[combo.selectedIndex].text;
var地址=文档
.getElementById(“fPersonal:inputDir”).value
+“,”+selectValue+“,“+”智利”;
//警报(地址);
//我们创建Geocoder对象
var geocoder=new google.maps.geocoder();
//我们发出指示地址的请求并调用函数
//geocodeResult发送所有获得的结果
地理编码({
“地址”:地址
},地理编码结果);
}
}
}
功能geocodeResult(结果、状态){
如果(results.length==1){
//埃斯塔斯酒店
如果(状态=‘正常’){
//如果找到结果,我们将居中并重新绘制地图
//这是为了在放置前移除任何销
变量映射选项={
缩放:15,
中心:结果[0].geometry.location,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=新的google.maps.map(文档
.getElementById(“fPersonal:map”),
地图选项);
//我在文本字段中获取纬度和经度
document.getElementById(“fPersonal:inputLatitud”).value=results[0]。geometry.location
.lat();
document.getElementById(“fPersonal:inputLongitud”).value=results[0]。geometry.location
.lng();
//fitBounds将根据您要查找的内容以正确的缩放比例放大地图
map.fitBounds(结果[0].geometry.viewport);
//我们用第一个结果的位置画一个标记
变量标记选项={
位置:结果[0]。几何体。位置
}
marker=新的google.maps.marker(markerOptions);
marker.setMap(map);
google.maps.event.addListener(映射,'单击',
功能(事件){
//警惕(5);
更新标记器(event.latLng);
});
}否则{
//如果没有结果或发生错误
//我们发出了一条带有错误的消息
//警报(“地理编码no tuvoéxito debido a:+状态);
document.getElementById(“fPersonal:inputLatitud”).value='';
document.getElementById(“fPersonal:inputLongitud”)。值=“”;
document.getElementById(“fPersonal:inputDir”)。值=“”;
}
}否则{
//如果没有结果或发生错误
//我们发出了一条带有错误的消息
//警报(“结果大于1:+results.length”);
document.getElementById(“fPersonal:inputLatitud”).value='';
document.getElementById(“fPersonal:inputLongitud”)。值=“”;
document.getElementById(“fPersonal:inputDir”)。值=“”;
}
}
//我更新了记分板上的位置
函数更新标记器(位置){
标记器。设置位置(位置);
更新标记位置(位置);
}
//我检索纬度、经度和方向,将其放入表单中
函数更新标记位置(latLng){
//警报(latLng.lat());
document.getElementById(“fPersonal:inputLatitud”).value=l