如何居中谷歌地图到所在位置的经纬度? [英] How to center a Google Map to a latitude and longitude location?

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

问题描述

考虑以下code:

  $('店')。点击(函数(){
    的console.log($(本)。数据('纬度')); // -1754.26265626
    的console.log($(本)。数据('东经')); // 65.262518
    的console.log(themap); //正确一个谷歌地图实例。    themap.setCenter(新经纬度($(本)。数据('纬度'),$(本)。数据('东经')));
});

按照文档,我可以使用 setCenter 方法,轻松地地图中心,但我不明白的文档所使用的符号。

请参阅:

 经纬度(纬度:号,LNG:编号,NOWRAP:布尔)

究竟如何使用呢?

我收到以下错误:

 未捕获的Ref​​erenceError:经纬度没有定义


解决方案

您必须使用

  themap.setCenter(新google.maps.LatLng($(本)。数据('纬度'),$(本)。数据('东经')));

JavaScript类是用 google.maps.ClassName()标记中引用的所有谷歌地图

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 setCenter method and easily center the map, but I don't understand the notation the docs are using.

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 

解决方案

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

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

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