如何将谷歌地图以纬度和经度位置为中心? [英] How to center a Google Map to a latitude and longitude location?

查看:26
本文介绍了如何将谷歌地图以纬度和经度位置为中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码:

$('.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')));
});

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

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

见:

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

我究竟如何使用它?

我收到错误:

Uncaught ReferenceError: LatLng is not defined 

推荐答案

你必须使用

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

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

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

这篇关于如何将谷歌地图以纬度和经度位置为中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆