html - 如何按经度和纬度在我的网站上显示谷歌地图

标签 html google-maps

我尝试使用这段代码:

<img id="small-map" height="198" width="254" alt="Google Map" src="https://maps.google.com/maps?q=24.197611,120.780512" />

但它在html页面上不起作用。

虽然当我使用这个时:

https://maps.google.com/maps?q=24.197611,120.780512

它可以工作,但就像一个谷歌页面

最佳答案

你好,这是示例代码

<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript" type="text/javascript">

    var map;
    var geocoder;
    function InitializeMap() {

        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions =
        {
            zoom: 8,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            disableDefaultUI: true
        };
        map = new google.maps.Map(document.getElementById("map"), myOptions);
    }

    function FindLocaiton() {
        geocoder = new google.maps.Geocoder();
        InitializeMap();

        var address = document.getElementById("addressinput").value;
        geocoder.geocode({ 'address': address }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });

            }
            else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });

    }


    function Button1_onclick() {
        FindLocaiton();
    }

    window.onload = InitializeMap;

</script>
</head>
<body>
<h2>Gecoding Demo JavaScript: </h2>
<table>
<tr>
<td>
    <input id="addressinput" type="text" style="width: 447px" />   
</td>
<td>
    <input id="Button1" type="button" value="Find" onclick="return Button1_onclick()" /></td>
</tr>
<tr>
<td colspan ="2">
<div id ="map" style="height: 253px" >
</div>
</td>
</tr>
</table>
</body>
</html>

关于html - 如何按经度和纬度在我的网站上显示谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16983017/

相关文章:

php - 不使用表单将文件上传到服务器?

javascript - `vertical-align: middle` 没有达到我的预期

html - 如何创建比标题宽的下拉菜单?

javascript - 来自 set_at 事件的谷歌地图可编辑多边形过滤器拖动事件

javascript - 从 javascript 中的 csv 文件中的坐标使用 GoogleMaps API

javascript - Google map 自定义标记

html - 在没有定义的单元格上显示边框是 Chrome 中的错误吗?

html - 图像溢出问题 (CSS)

ios - 谷歌地图 404 页面在路由时找不到错误

ios - Google map openNowStatus 始终返回未知(状态 2)