[英]Google map center (lat/lng) issue
The script that I use for google map in my site is 我在网站上用于Google地图的脚本是
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js"></script>
I get the center from a hidden input by 我从隐藏输入获得中心
var pos = $('#lat_lng').val();
in my console it pos
print as 23.810332,90.41251809999994
在我的控制台中它将
pos
打印为23.810332,90.41251809999994
The problem is if I use var myCenter=new google.maps.LatLng(pos);
问题是如果我使用
var myCenter=new google.maps.LatLng(pos);
google map doesnot work but if I use 谷歌地图不起作用,但如果我使用
var myCenter=new google.maps.LatLng(23.810332,90.41251809999994);
It works fine. 工作正常。 Where is the main problem?
主要问题在哪里? Thank you
谢谢
主要问题是,这个new google.maps.LatLng
从double类型中接受了2个参数,因此,当您传递Pos
时,您会从string
类型中传递一个参数,但是当您传递23.810332,90.41251809999994
您会从double
类型中传递两个参数
You need to use the correct constructor for the LatLng, have a look at the documentation . 您需要为LatLng使用正确的构造函数,请参阅文档 。
map.setCenter(new google.maps.LatLng(-34, 151));
Split your pos variable and then use each Lat and Long in the constructor as follows. 拆分pos变量,然后按如下所示在构造函数中使用每个纬度和经度。
var pos_array = pos.split(",");
var myCenter=new google.maps.LatLng(pos_array[0], pos_array[1]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.