javascript inside cffunction
I have a really stupid question, but I need to use some javascript in a cffunction in a cfc.
Is this possible?
I am trying to use google maps geocode to get the latitude and longitude for addresses and it works in a cfm page, but doesn't in the cffunction.
the below converts the data to json and sends it to a cfc, the cfc then write the data to a file.
the overall goal is to call the service and get this information back in cfml if all possible. we are using google maps api v3.
here is my code:
testget.cfm
<cfajaxproxy cfc="cfc.mycfc" jsclassname="gs">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
geocoder = new google.maps.Geocoder();
var address = 'your street, your city, your state, your zipcode';
geocoder.geocode( {address: address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results.length) {
// You should always check that a result was returned, as it is
// possible to return an empty results object.
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
var e = new gs();
var jsonObj = ColdFusion.JSON.encode(results[0].geometry.location);
var json = e.updateLatLng(jsonObj);
}
}
});
</script>
---------------------------------------------------------------------------------------------------------------------
mycfc.cfc
<cffunction name="updateLatLng" access="remote" >
<cfargument name="latlng" >
<cfset i = deserializeJSON(latlng) >
<cfset lat = i.Yd />
<cfset lng = i.$d />
<cffile action = "write"
file = "C:\ColdFusion8\wwwroot\dev.zipoodle.com\jsontest.txt"
output = "cfclat = #lat# and cfclng = #lng#" >
</cffunction>
