javascript 如何将谷歌地图以经纬度位置居中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13942897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:15:15  来源:igfitidea点击:

How to center a Google Map to a latitude and longitude location?

javascriptapigoogle-maps

提问by sergserg

Consider the following code:

考虑以下代码:

$('.stores').click(function() {
    console.log($(this).data('latitude'));  // -1754.26265626
    console.log($(this).data('longitude')); // 65.262518
    console.log(themap); // Properly a Google Map instance.

    themap.setCenter(new LatLng($(this).data('latitude'), $(this).data('longitude')));
});

According to the documentation, I can use the setCentermethod and easily center the map, but I don't understand the notation the docs are using.

根据文档,我可以使用该setCenter方法并轻松地将地图居中,但我不明白文档使用的符号。

See:

看:

LatLng(lat:number, lng:number, noWrap?:boolean)

How exactly do I use this?

我究竟如何使用它?

I'm getting the error:

我收到错误:

Uncaught ReferenceError: LatLng is not defined 

回答by Adam Elsodaney

You have to use

你必须使用

themap.setCenter(new google.maps.LatLng($(this).data('latitude'), $(this).data('longitude')));

All Google Maps javascript classes are referenced with the google.maps.ClassName()notation

所有 Google Maps javascript 类都使用google.maps.ClassName()符号引用