如何通过经度和纬度在我的网站上显示谷歌地图

Ser*_*gey 5 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" />
Run Code Online (Sandbox Code Playgroud)

但它不适用于html页面.

虽然我使用这个:

https://maps.google.com/maps?q=24.197611,120.780512
Run Code Online (Sandbox Code Playgroud)

它的工作原理,但就像一个谷歌页面

Ran*_*esh 12

嗨,这里是示例代码

<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>
Run Code Online (Sandbox Code Playgroud)


PiL*_*LHA 7

查看此文档https://developers.google.com/maps/documentation/imageapis/

<img src="http://maps.googleapis.com/maps/api/staticmap?center=-15.800513,-47.91378&zoom=11&size=200x200&sensor=false">
Run Code Online (Sandbox Code Playgroud)