开发者

JSON Result to Markers and Info Box on Google Maps

JSON results:

[{"Company":"Compa开发者_运维知识库ny1","Country":"US","Phone":"209-555-8400","Website":"www.mywebsite.com","Latitude":35.782,"Longitude":-120.2269},
{"Company":"Company2","Country":"US","Phone":"909-555-5500","Website":"www.mywebsite.com","Latitude":36.112782,"Longitude":-111.52691},
{"Company":"Company3","Country":"US","Phone":"702-555-5200","Website":"www.mywebsite.com","Latitude":37.0427,"Longitude":-112.1818},
{"Company":"Company4","Country":"US","Phone":"602-555-5600","Website":"www.mywebsite.com","Latitude":38.4369,"Longitude":-113.8671},
{"Company":"Company5","Country":"US","Phone":"800-555-4716","Website":"www.mywebsite.com","Latitude":39.244946,"Longitude":-114.211941}]

Javascript in View


        var locations = ["How can I get my JSON results in here"]

        var map = new google.maps.Map(document.getElementById('map_canvas'), {
            zoom: 2,
            center: new google.maps.LatLng(40.0, -35.0),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        var infowindow = new google.maps.InfoWindow();

        var marker, i;

        for (i = 0; i 

I need something like this:

var locations = ['Company1 209-555-8400 US www.mywebsite.com', 35.78, -120.23]


Have a look at parsing the json into an object. Something like JSON.net would be useful.


you can use jquery parser

var dataJson = $.parseJSON(data);

then you loop through the array

for(var i=0;i<dataJson.length;i++)
{
   var company = dataJson[i].Company;
   ....
}

alternatively if you want the ready string above, you can set it in server side

Type myType = myObject.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
String.Join(" ",  props.select(p => p.GetValue(yourObject,null)))

in concise way

String.Join(" ",  (List<PropertyInfo>)(object.GetType().GetProperties()).select(p => p.GetValue(yourObject,null)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜