C# 谷歌地图显示错误的位置

C# 谷歌地图显示错误的位置,c#,asp.net,vb.net,google-maps,C#,Asp.net,Vb.net,Google Maps,我获得了一个密钥并将其插入到我的代码(asp.net)中。尽管我在代码中插入了一个新地址,但谷歌地图显示了教程示例Iam的默认位置,请参见下文 <script type="text/javascript"> function initialize() { var myLatlng = new google.maps.LatLng(-34.397, 150.644) var mapOptions = { center: myLatlng,

我获得了一个密钥并将其插入到我的代码(asp.net)中。尽管我在代码中插入了一个新地址,但谷歌地图显示了教程示例Iam的默认位置,请参见下文

    <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);
}

函数初始化(){
var mylatng=new google.maps.LatLng(-34.397150.644)
变量映射选项={
中心:myLatlng,
缩放:8,
mapTypeId:google.maps.mapTypeId.ROADMAP,
马克:对
};
var map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“南非比勒陀利亚7号阳光沙滩”
});
marker.setMap(map);
}
使用以下代码:

我改变了:

<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>

函数初始化(){
var mylatng=new google.maps.LatLng(-34.397150.644)
变量映射选项={
中心:myLatlng,
缩放:8,
mapTypeId:google.maps.mapTypeId.ROADMAP,
马克:对
};
var map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“南非比勒陀利亚7号阳光沙滩”
});
marker.setMap(map);
}
google.maps.event.addDomListener(窗口“加载”,初始化);

问题在于您更改了标题,但这并不是更改显示内容或标记位置的原因

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


函数初始化(){
//为了改变显示内容和标记位置,必须改变这些坐标吗
var mylatng=new google.maps.LatLng(-25.755372,28.212204);
//在你吃这个之前。
//var mylatng=new google.maps.LatLng(-34.397150.644)
变量映射选项={
中心:myLatlng,
缩放:14,
mapTypeId:google.maps.mapTypeId.ROADMAP,
马克:对
};
var map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
google.maps.event.addListener(映射,“单击”,函数(evt){
控制台日志(evt.latLng);
});
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“这是标题,在地址中没有任何影响:7 sunnyside sands,南非比勒陀利亚”
});
marker.setMap(map);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
如果您想使用人类可读的地址来显示标记等,您必须阅读


你有一个例子

欢迎光临。如果这个答案对你有用,请将它标记为已回答。我建议你也读一下这个(你将获得一枚徽章):
<!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>