本文介绍了在Google地图上访问Javascript阵列以放置地图标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组:
var = CITIES {
布宜诺斯艾利斯:
{ 纬度:-34.6084,经度:-58.3732,
圣地亚哥:
{纬度:-33.4254,经度:-70.5665},
哈博罗内:
{纬度: -24.6541,经度:25.9087},
...
};
我需要在2D Google地图上放置标记;我试着用这个函数来做:
/ *
* void
* mark()
*
*标出世界各地留学计划的地点地图
* /
功能标记()
{
//标记(CITIES城市中的VAR城市)
{
//地图上的工厂城市
new google.maps.Marker({
icon:http:// google-maps-icons.googlecode.com/files/smallcity.png,
map:map,
position:new google.maps.LatLng(CITIES [city] .latitude,CITIES [city]。经度),
标题:'CITIES [city]'
});
$ b $ p
$ b js控制台给我一个错误说:
缺少变量名称
[Break on this error] var = CITIES {\ n
code>
我知道这个错误与我使用城市参数访问CITIES有关,但是如何解决这个问题并获取必要的信息?
解决方案 var = CITIES {
不对,请使用<$ c $首先说你想创建一个变量( var $>)。 c $ c>),然后指定它的名称( CITIES
),然后分配一个值(可选地, = ...
)。
I have an array:
var = CITIES {
"Buenos Aires":
{latitude: -34.6084, longitude: -58.3732},
"Santiago":
{latitude: -33.4254, longitude: -70.5665},
"Gaborone":
{latitude: -24.6541, longitude: 25.9087},
...
};
I need to place markers on a 2D Google Map; I try to do it with this function:
/*
* void
* mark()
*
* Markes locations of study abroad programs all around the world map
*/
function mark()
{
// mark programs
for (var city in CITIES)
{
// plant cities on map
new google.maps.Marker({
icon: "http://google-maps-icons.googlecode.com/files/smallcity.png",
map: map,
position: new google.maps.LatLng(CITIES[city].latitude, CITIES[city].longitude),
title: 'CITIES[city]'
});
}
}
The js console is giving me an error saying that:
missing variable name
[Break on this error] var = CITIES {\n
I know the error has to do with me accessing CITIES with city parameter, but how do I fix this and access the necessary information?
解决方案 var = CITIES {
is wrong, use var CITIES = {
instead.
First say that you want to create a variable (var
), then specify its name (CITIES
) and then assign a value (optionally, =...
).
这篇关于在Google地图上访问Javascript阵列以放置地图标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-08 04:38