English 中文(简体)
jquery json 阵列 Googlemap 谷歌图
原标题:jquery json array Googlemap

Got probs with a nice exmaple. I used this Google map example and it is working with the local array created in the javascript: http://jsfiddle.net/jFMQ5/2/

现在我只需要改变它 从php获得阵列。

步骤是:

  • create array in php
  • convert array to json using json_encode
  • grap it in javascript

如何在 json 而不是 阵列上循环 。 或如何从 json 创建 javascript 阵列

在我的喷射器里,我得到了这个(也充满了发型错误, 但我猜这是另一个问题)

var arrAddress = ["Sir vej 3 7500 Holstebro","Ivar Lundgaardsvej 8 7500 Holstebro","Hu00f8jtoftvej 6 7500 Holstebro","Svalevu00e6nget 22 7500 Holstebro","Ringku00f8bingvej 21 7500 Holstebro","Elkju00e6rvej 90 7500 Holstebro","Hovedgaden 2 7500 Holstebro","Skolegade 32 7500 Holstebro","Fuglsangvej 2 7500 Holstebro","Slu00e5envej 150 7500 Holstebro","Burvej 2A Idom 7500 Holstebro"];

在jsfidd 例子中,它期待这样的阵列:

$arrAddress[0] = "Sir vej 3 7500 Holstebro";
$arrAddress[1] = "Ivar Lundgaardsvej 8 7500 Holstebro"
etc. etc.

如何使 Jsfidle 链接与这个 json 字符串有效, 而不是本地定义的数组?

UPDATE PHP is creating the array like this:

// in PHP //
While(...) {
    $arrAddress[] = $row[ address ].   .$row[ zip ].   .$row[ city ];
}
// after while
$arrAddress = json_encode($arrAddress);
// end php //

// in javascript //
var addAddress = {$arrAddress}
问题回答

您确定您在 javascript 中返回了 JSON 对象吗? 请尝试做一个 < code> concole.log (Address) , 看看它是否返回了字符串或对象。 这也将会显示“ array” 索引( 以铬为单位 ) 。

也试着分析Json的弦

var addAddress = $.parseJSON({$arrAddress});




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签