|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
problems with json and google maps
HiSeamus Campbell 04/20/12 04:25 A I've had similar problems to this when trying to serialise JSON for a jQueryEdward Chanter 04/20/12 04:40 A I would use this insteadAndrew Scott 04/20/12 05:06 A Scott Stroz put a function on CFLib.org that can help.Geoffrey Bentz 04/20/12 09:28 A Thanks to all who replied. I used Edward Chanter solution which gave me the json object in what appeared to be the correct format but I still couldn't get it to work. I'm going to advertise to get someone to help me on cf-jobs.Seamus Campbell 04/20/12 06:08 P My serializeCFJSON JQuery plugin might help you with thisSteve 'Cutter' Blades 04/30/12 08:33 A Hi I'm trying to populate a google map from a cfquery. I serializeJSON the query then try and use that json object to populate the map. I'm using code from Gabriel Svennerberg's Google Maps books (see code below), but my json object from the query looks very different (in format) from the example json object that Svennerberg shows. His is in this format: var json = [ { "title": "Stockholm", "lat": 59.3, "lng": 18.1, "description": "Stockholm is the capital and the largest city of Sweden and constitutes the most populated urban area in Scandinavia with a population of 2.1 million in the metropolitan area (2010)" }, { "title": "Oslo", "lat": 59.9, "lng": 10.8, "description": "Oslo is a municipality, and the capital and most populous city of Norway with a metropolitan population of 1,442,318 (as of 2010)." } ] and mine is like this: {"COLUMNS":["BUSINESS_NAME","LATITUDE","LONGITUDE"],"DATA":[["sdfdsf Books",-36.890408,121.154751],["dsdsdsd Booksellers",-14.921735,18.602189],["fff ints",-17.8451823,195.0541819]]} Is there a way I can convert my query to a json object with the same format as Svennerberg's? any halp gratefully received <cfsilent> <cfquery name="get_map_details" datasource="#application.main_dsn#"> SELECT business_name, latitude, longitude FROM tbl_premises WHERE latitude <> 0 </cfquery> </cfsilent> <cfset json_query = serializeJSON(get_map_details,false)> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script><script type="text/javascript"> (function() { window.onload = function() { // Creating a new map var map = new google.maps.Map(document.getElementById("map"), { center: new google.maps.LatLng(-24.327, 140.273), zoom: 5, mapTypeId: google.maps.MapTypeId.ROADMAP }); // Creating a global infoWindow object that will be reused by all markers var infoWindow = new google.maps.InfoWindow(); // Looping through the JSON data for (var i = 0, length = json_query.length; i < length; i++) { var data = json_query[i], latLng = new google.maps.LatLng(data.latitude, data.longitude); // Creating a marker and putting it on the map var marker = new google.maps.Marker({ position: latLng, map: map, title: data.business_name }); } } })(); </script> </head> <body> <div id = "map" style="width: 800px; height: 500px; border: 1px solid #000;"></div> </body> </html> I've had similar problems to this when trying to serialise JSON for a jQuery plugin. The only solution I found that worked is detailed here: <!--- get the matches ---> <cfquery name="q" datasource="#request.ds#"> select product_id as value, product_title as label from products where product_title like <cfqueryparam value="%#url.term#%" /> </cfquery> <!--- where we'll hold the data to convert to JSON ---> <cfset data = [] /> <cfoutput query="q"> <!--- create a new structure on each iteration, forcing lowercase keys ---> <cfset obj = { "label" = label, "value" = value } /> <!--- push this match onto the array ---> <cfset arrayappend(data, obj) /> </cfoutput> <!--- serialize the new structure ---> <cfoutput>#serializeJSON(data)#</cfoutput> http://goo.gl/VGxlA Credit goes to Eric Hynds not me for this one. HTH > Hi > I'm trying to populate a google map from a cfquery. > I serializeJSON the query then try and use that json object to populate the ----- Excess quoted text cut - see Original Post for more ----- Sweden and ----- Excess quoted text cut - see Original Post for more ----- populous ----- Excess quoted text cut - see Original Post for more ----- format ----- Excess quoted text cut - see Original Post for more ----- { ----- Excess quoted text cut - see Original Post for more ----- I would use this instead http://www.epiphantastic.com/cfjson/ -- Regards, Andrew Scott WebSite: http://www.andyscott.id.au/ Google+: http://plus.google.com/108193156965451149543 ----- Excess quoted text cut - see Original Post for more ----- Scott Stroz put a function on CFLib.org that can help. http://cflib.org/udf/queryConvertForjqGrid He wrote it to convert a query to a json format for jQuery's jqGrid plugin, but I started using it this week to send json data for jQuery templates. It only took a slight tweak since the jQuery template did not need the extra page and total record information that jqGrid needs. Geoffrey Thanks to all who replied. I used Edward Chanter solution which gave me the json object in what appeared to be the correct format but I still couldn't get it to work. I'm going to advertise to get someone to help me on cf-jobs. My serializeCFJSON JQuery plugin might help you with this https://github.com/cutterbl/serializeCFJSON Steve 'Cutter' Blades Adobe Community Professional Adobe Certified Expert Advanced Macromedia ColdFusion MX 7 Developer ____________ http://cutterscrossing.com Co-Author "Learning Ext JS 3.2" Packt Publishing 2010 https://www.packtpub.com/learning-ext-js-3-2-for-building-dynamic-desktop-style-user-interfaces/book "The best way to predict the future is to help create it" On 4/20/2012 6:07 PM, Seamus Campbell wrote: > Thanks to all who replied. I used Edward Chanter solution which gave me the json object in what appeared to be the correct format but I still couldn't get it to work. I'm going to advertise to get someone to help me on cf-jobs.
|
June 19, 2013
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||