谷歌地图显示错误的位置

时间:2013-12-09 05:25:40

标签: c# asp.net vb.net google-maps

我获得了一个密钥并将其插入到我的代码(asp.net)中。然而谷歌地图显示了我使用的教程示例的默认位置,虽然我在代码中插入了新地址,请参阅下面的

    <script type="text/javascript">
function initialize() {
    var myLatlng = new google.maps.LatLng(-34.397, 150.644)
    var mapOptions = {
        center: myLatlng,
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        marker: true
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: " 7 sunnyside sands , Pretoria, South Africa"
    });
    marker.setMap(map);
}

2 个答案:

答案 0 :(得分:0)

使用此代码:

我改变了:

<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script type="text/javascript">
function initialize() {
    var myLatlng = new google.maps.LatLng(-34.397, 150.644)
    var mapOptions = {
        center: myLatlng,
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        marker: true
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: " 7 sunnyside sands , Pretoria, South Africa"
    });
    marker.setMap(map);

}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="map_canvas" style="width:500px;height:380px;"></div>
</body>
</html>

答案 1 :(得分:0)

问题是你改变了 标题 ,但这不是改变显示的内容或标记的位置。

为了更改您想要的位置,您必须设置坐标,如以下示例所示(查看myLatlng变量):

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false"></script>
</head>

<body>
    <div id="map_canvas" style="width:500px;height:380px;"></div>
    <script type="text/javascript">
        function initialize() {
            // Are these coordinates that has to be changed in order to change what it is showed and the marker position
            var myLatlng = new google.maps.LatLng(-25.755372, 28.212204);
            // before you had this. 
            //var myLatlng = new google.maps.LatLng(-34.397, 150.644)

            var mapOptions = {
                center: myLatlng,
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                marker: true
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

            google.maps.event.addListener(map, "click", function(evt) {
                console.log(evt.latLng);
            });

            var marker = new google.maps.Marker({
                position: myLatlng,
                map: map,
                title: "This is the title and don't have any effect in the address showed: 7 sunnyside sands , Pretoria, South Africa"
            });
            marker.setMap(map);
        }

        google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>

如果您想使用人类可读的地址来显示标记,那么您必须阅读DirectionService

你有一个关于here

的exameple