JSON 结果到 Google 地图上的标记和信息框
JSON 结果:
[{"Company":"Company1","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
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
我需要这样的东西:
var locations = ['Company1 209-555-8400 US www.mywebsite.com', 35.78, -120.23]
JSON results:
[{"Company":"Company1","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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下将 json 解析为对象。像 JSON.net 这样的东西会很有用。
Have a look at parsing the json into an object. Something like JSON.net would be useful.
您可以使用 jquery 解析器,
然后循环遍历数组
,或者如果您想要上面准备好的字符串,您可以在服务器端
以简洁的方式设置它
you can use jquery parser
then you loop through the array
alternatively if you want the ready string above, you can set it in server side
in concise way