Collaborama About Help Contact Anonymous [login] Source: site.view [edit] Function name: geocode Arguments: addr Description: Returns lat long results given an address string Page type: webl Render function: Module: global Page source: // use localsearchmaps.com/geo free geocoder, which returns text in the form: // map.centerAndZoom(new GPoint(-99.1419, 39.5275), 4); /* LocalSearchMaps free geocoder seems defunct. var P = GetURL("http://www.localsearchmaps.com/geo/?loc=" + Url_Encode(addr)); var LatLong = Pat(P, `([-\d.]*)`); if (Size(LatLong) > 2) then [. long= LatLong[1][1], lat= LatLong[2][1], label=addr .] else Size(LatLong) end; */ /* Yahoo geocode seems defunct // Use YahooLocal's new Places API instead var P = GetURL("http://where.yahooapis.com/geocode?q=" + Url_Encode(addr) + "&appid=wubhuboaa") ? nil; */ var P = GetURL("https://maps.googleapis.com/maps/api/geocode/json?address=" + Url_Encode(addr) + "&key=AIzaSyAO2RntyX5IUgDJmXO-i39U06wwIhKwdEE") ? nil; var res = [. label=addr .]; var getVal = fun(P, field) var val = nil; every comp in Elem(P, "types") do if Str_Trim(Text(comp)) == field then var E = Elem(P, "short_name") inside Parent(comp); if Size(E) > 0 then val = Str_Trim(Text(E[0])); end end end; return val end; var getVal2 = fun(P, field) var val = nil; var E = Elem(P, field); if Size(E) > 0 then val = Str_Trim(Text(E[0])) end; return val end; if (P != nil) then var Lats = Elem(P, "lat") inside Elem(P, "location"); var Longs = Elem(P, "lng") inside Elem(P, "location"); if (Size(Lats) == 1) and (Size(Longs) == 1) then res.long := Str_Trim(Text(Longs[0])); res.lat := Str_Trim(Text(Lats[0])); res.desc := Pretty(P); end; res["postalCode"] := getVal(P, "postal_code"); res["postalCodeSuffix"] := getVal(P, "postal_code_suffix"); res["subpremise"] := getVal(P, "subpremise"); res["streetNumber"] := getVal(P, "street_number"); res["street"] := getVal(P, "route"); res["neighborhood"] := getVal(P, "neighborhood"); res["city"] := getVal(P, "locality"); res["county"] := getVal(P, "administrative_area_level_2"); res["state"] := getVal(P, "administrative_area_level_1"); res["country"] := getVal(P, "country"); res["formatted"] := getVal2(P, "formatted_address"); end; res;