JSON结果到谷歌地图上的标记和信息框
本文关键字:信息 结果 谷歌地图 JSON | 更新日期: 2023-09-27 17:57:30
JSON结果:
[{"公司":"Company1","国家":"美国","电话":"209-555-8400","网站":"www.mywebsite.com","纬度":35.782,"经度":-120.2269},{"公司":"公司2","国家":"美国","电话":"909-555-5500","网站":"www.mywebsite.com","纬度":36.112782,"经度":-111.52691},{"公司":"公司3","国家":"美国","电话":"702-555-5200","网站":"www.mywebsite.com","纬度":37.0427,"经度":-112.1818},{"公司":"公司4","国家":"美国","电话":"602-555-5600","网站":"www.mywebsite.com","纬度":38.4369,"经度":-113.8671},{"公司":"公司5","国家":"美国","电话":"800-555-4716","网站":"www.mywebsite.com","纬度":39.244946,"经度":-114.211941}]
视图中的Javascript
var locations=["如何在此处获取JSON结果"]var map=new google.maps.map(document.getElementById('map_canvas'){缩放:2,中心:新谷歌地图。LatLng(40.0,-35.0),mapTypeId:google.maps.mapTypeId.ROADMAP});var infowindow=新的google.maps.infowindow();var标记,i;对于(i=0;i
我需要这样的东西:
var locations='Company1 209-555-8400 US www.mywebsite.com',35.78,-120.23]
了解如何将json解析为对象。像JSON.net这样的东西会很有用。
您可以使用jquery解析器
var dataJson = $.parseJSON(data);
然后你循环通过阵列
for(var i=0;i<dataJson.length;i++)
{
var company = dataJson[i].Company;
....
}
或者,如果你想要上面的就绪字符串,你可以在服务器端中设置它
Type myType = myObject.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
String.Join(" ", props.select(p => p.GetValue(yourObject,null)))
以简洁的方式
String.Join(" ", (List<PropertyInfo>)(object.GetType().GetProperties()).select(p => p.GetValue(yourObject,null)))