Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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
Google maps 特定纬度和经度的谷歌地图搜索框_Google Maps_Search_Google Maps Api 3 - Fatal编程技术网

Google maps 特定纬度和经度的谷歌地图搜索框

Google maps 特定纬度和经度的谷歌地图搜索框,google-maps,search,google-maps-api-3,Google Maps,Search,Google Maps Api 3,我是谷歌地图/API的新手,我想用javascript创建一个谷歌搜索框。我还希望这个谷歌搜索框是自动完成的。这些纬度/经度的列表将存储在一个javascript文件中。通过读取此文件,将为谷歌地图创建特定的搜索框 这个很好用 <html> <head> <title></title> <meta charset="UTF-8"> <meta name="viewport" content="width=d

我是谷歌地图/API的新手,我想用javascript创建一个谷歌搜索框。我还希望这个谷歌搜索框是自动完成的。这些纬度/经度的列表将存储在一个javascript文件中。通过读取此文件,将为谷歌地图创建特定的搜索框

这个很好用

<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
    <style>
        #gmap_canvas {
            height: 700px;
            position: relative;
            width: 900px;
        }
        .actions {
            background-color: #FFFFFF;
            bottom: 30px;
            padding: 10px;
            position: absolute;
            right: 30px;
            z-index: 2;

            border-top: 1px solid #abbbcc;
            border-left: 1px solid #a7b6c7;
            border-bottom: 1px solid #a1afbf;
            border-right: 1px solid #a7b6c7;
            -webkit-border-radius: 12px;
            -moz-border-radius: 12px;
            border-radius: 12px;
        }
        .actions label {
            display: block;
            margin: 2px 0 5px 10px;
            text-align: left;
        }
        .actions input, .actions select {
            width: 85%;
        }
        .button {
            background-color: #d7e5f5;
            background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #d7e5f5), color-stop(100%, #cbe0f5));
            background-image: -webkit-linear-gradient(top, #d7e5f5, #cbe0f5);
            background-image: -moz-linear-gradient(top, #d7e5f5, #cbe0f5);
            background-image: -ms-linear-gradient(top, #d7e5f5, #cbe0f5);
            background-image: -o-linear-gradient(top, #d7e5f5, #cbe0f5);
            background-image: linear-gradient(top, #d7e5f5, #cbe0f5);
            border-top: 1px solid #abbbcc;
            border-left: 1px solid #a7b6c7;
            border-bottom: 1px solid #a1afbf;
            border-right: 1px solid #a7b6c7;
            -webkit-border-radius: 12px;
            -moz-border-radius: 12px;
            border-radius: 12px;
            -webkit-box-shadow: inset 0 1px 0 0 white;
            -moz-box-shadow: inset 0 1px 0 0 white;
            box-shadow: inset 0 1px 0 0 white;
            color: #1a3e66;
            font: normal 11px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
            line-height: 1;
            margin-bottom: 5px;
            padding: 6px 0 7px 0;
            text-align: center;
            text-shadow: 0 1px 1px #fff;
            width: 150px;
        }
        .button:hover {
            background-color: #ccd9e8;
            background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ccd9e8), color-stop(100%, #c1d4e8));
            background-image: -webkit-linear-gradient(top, #ccd9e8, #c1d4e8);
            background-image: -moz-linear-gradient(top, #ccd9e8, #c1d4e8);
            background-image: -ms-linear-gradient(top, #ccd9e8, #c1d4e8);
            background-image: -o-linear-gradient(top, #ccd9e8, #c1d4e8);
            background-image: linear-gradient(top, #ccd9e8, #c1d4e8);
            border-top: 1px solid #a1afbf;
            border-left: 1px solid #9caaba;
            border-bottom: 1px solid #96a3b3;
            border-right: 1px solid #9caaba;
            -webkit-box-shadow: inset 0 1px 0 0 #f2f2f2;
            -moz-box-shadow: inset 0 1px 0 0 #f2f2f2;
            box-shadow: inset 0 1px 0 0 #f2f2f2;
            color: #163659;
            cursor: pointer;
        }
        .button:active {
            border: 1px solid #8c98a7;
            -webkit-box-shadow: inset 0 0 4px 2px #abbccf, 0 0 1px 0 #eeeeee;
            -moz-box-shadow: inset 0 0 4px 2px #abbccf, 0 0 1px 0 #eeeeee;
            box-shadow: inset 0 0 4px 2px #abbccf, 0 0 1px 0 #eeeeee;
        }
    </style>
    <script type="text/javascript">
        var geocoder;
        var map;
        function initialize() {
            geocoder = new google.maps.Geocoder();

            var myLatlng = new google.maps.LatLng(40, 111);
            var myOptions = {// default map options
                center: new google.maps.LatLng(40, 111),
                zoom: 6,
                center: myLatlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);
        }

        function findAddress() {
            var address = document.getElementById("gmap_where").value;

            geocoder.geocode({'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) { // and, if everything is ok

                    var addrLocation = results[0].geometry.location;
                    map.setCenter(addrLocation);

                    document.getElementById('lat').value = results[0].geometry.location.lat();
                    document.getElementById('lng').value = results[0].geometry.location.lng();

                    var addrMarker = new google.maps.Marker({
                        position: addrLocation,
                        map: map,
                        title: results[0].formatted_address,
                        icon: 'map_g.png'
                    });
                } else {
                    alert('Geocode was not successful for the following reason: ' + status);
                }
            });
        }

        google.maps.event.addDomListener(window, 'load', initialize);

    </script>

</head>
<body>
    <div id="gmap_canvas"></div>
    <div class="actions">
        <div class="button">
            <label for="gmap_where">Where:</label>
            <input id="gmap_where" type="text" name="gmap_where" /></div>
        <div id="button2" class="button" onclick="findAddress();
        return false;">Search for address</div>

        <input type="hidden" id="lat" name="lat" value="40.7143528" />
        <input type="hidden" id="lng" name="lng" value="-74.0059731" />
    </div>

</body>

#gmap_帆布{
高度:700px;
位置:相对位置;
宽度:900px;
}
.行动{
背景色:#FFFFFF;
底部:30px;
填充:10px;
位置:绝对位置;
右:30px;
z指数:2;
边框顶部:1px实心#abbcc;
左边框:1px实心#a7b6c7;
边框底部:1px实心#a1afbf;
右边框:1px实心#a7b6c7;
-webkit边界半径:12px;
-moz边界半径:12px;
边界半径:12px;
}
.行动标签{
显示:块;
利润率:2px0.5px10px;
文本对齐:左对齐;
}
.actions输入,.actions选择{
宽度:85%;
}
.按钮{
背景色:#d7e5f5;
背景图像:-webkit渐变(线性、左上、左下、颜色停止(0%、#d7e5f5)、颜色停止(100%、#cbe0f5));
背景图像:-webkit线性渐变(顶部,#d7e5f5,#cbe0f5);
背景图像:-moz线性渐变(顶部,#d7e5f5,#cbe0f5);
背景图像:-ms线性渐变(顶部,#d7e5f5,#cbe0f5);
背景图像:-o-线性梯度(顶部,#d7e5f5,#cbe0f5);
背景图像:线性渐变(顶部,#d7e5f5,#cbe0f5);
边框顶部:1px实心#abbcc;
左边框:1px实心#a7b6c7;
边框底部:1px实心#a1afbf;
右边框:1px实心#a7b6c7;
-webkit边界半径:12px;
-moz边界半径:12px;
边界半径:12px;
-webkit盒阴影:嵌入0 1px 0 0白色;
-moz盒阴影:嵌入0 1px 0 0白色;
框阴影:嵌入0 1px 0 0白色;
颜色:#1a3e66;
字体:普通11px“Lucida Grande”、“Lucida Sans Unicode”、“Lucida Sans”、日内瓦、威尔达纳、无衬线;
线高:1;
边缘底部:5px;
填充:6px0 7px0;
文本对齐:居中;
文本阴影:0 1px 1px#fff;
宽度:150px;
}
.按钮:悬停{
背景色:#ccd9e8;
背景图像:-webkit渐变(线性、左上、左下、颜色停止(0%、#ccd9e8)、颜色停止(100%、#c1d4e8));
背景图像:-webkit线性渐变(顶部,#ccd9e8,#c1d4e8);
背景图像:-moz线性梯度(顶部,#ccd9e8,#c1d4e8);
背景图像:-ms线性梯度(顶部,#ccd9e8,#c1d4e8);
背景图像:-o-线性梯度(顶部,#ccd9e8,#c1d4e8);
背景图像:线性渐变(顶部,#ccd9e8,#c1d4e8);
边框顶部:1px实心#a1afbf;
左边框:1px实心#9caaba;
边框底部:1px实心#96a3b3;
右边框:1px实心#9caaba;
-webkit盒阴影:插入0 1px 0 0#f2f2;
-莫兹盒阴影:插入0 1px 0 0#f2f2;
框阴影:插入0 1px 0 0#f2f2;
颜色:#163659;
光标:指针;
}
.按钮:激活{
边框:1px实心#8c98a7;
-webkit盒阴影:插入0 0 4px 2px#abbcf,0 0 1px 0#eeeeee;
-moz盒阴影:插入0 0 4px 2px#abbcf,0 0 1px 0#eeee;
盒影:插入0 0 4px 2px#abbcf,0 0 1px 0#eeeeee;
}
var地理编码器;
var映射;
函数初始化(){
geocoder=新的google.maps.geocoder();
var mylatng=newgoogle.maps.LatLng(40111);
var myOptions={//默认映射选项
中心:新google.maps.LatLng(40111),
缩放:6,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById('gmap_canvas'),myOptions);
}
函数findAddress(){
var address=document.getElementById(“gmap_where”).value;
geocoder.geocode({'address':address},函数(结果,状态){
如果(status==google.maps.GeocoderStatus.OK){//,如果一切正常
var addrLocation=results[0]。geometry.location;
地图设置中心(地址位置);
document.getElementById('lat')。value=results[0]。geometry.location.lat();
document.getElementById('lng')。value=results[0]。geometry.location.lng();
var addrMarker=new google.maps.Marker({
位置:addrLocation,
地图:地图,
标题:结果[0]。格式化的\u地址,
图标:“map_g.png”
});
}否则{
警报('地理编码因以下原因未成功:'+状态);
}
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
哪里:
搜索地址