This example demonstrates how to use HTTP connections to geocode a lat/long address using Google's geocoding service.
1 Example Code
Copy
<xsql-script> <body> <set name='p_lat' type='decimal'>41.404047</set> <set name='p_lng' type='decimal'>2.117312</set> <!-- =================================================================================== --> <!-- Set lat long --> <!-- =================================================================================== --> <set name='m_latlng'><string.format><string>%f,%f</string><p_lat/><p_lng/></string.format></set> <!-- Set your Google key --> <set name='m_key'>YOUR_API_KEY</set> <!-- =================================================================================== --> <!-- Build the Google URL --> <!-- =================================================================================== --> <set name='m_url'><string>https://maps.googleapis.com/maps/api/geocode/xml?latlng=<m_latlng/>&key=<m_key/>&sensor=false</string></set> <set name='m_xml'> <http.connection.read encoding="utf-8"> <http.connection url="#m_url" /> </http.connection.read> </set> <return><m_xml/></return> </body> </xsql-script>
+---------------------------------------------------------------------------------------------+
|(constant_1) |
+---------------------------------------------------------------------------------------------+
|<?xml version="1.0" encoding="UTF-8"?> |
|<GeocodeResponse> |
| <status>OK</status> |
| <result> |
| <type>street_address</type> |
| <formatted_address>Carrer d'Isaac Albéniz, 1, 08017 Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>1</long_name> |
| <short_name>1</short_name> |
| <type>street_number</type> |
| </address_component> |
| <address_component> |
| <long_name>Carrer d'Isaac Albéniz</long_name> |
| <short_name>Carrer d'Isaac Albéniz</short_name> |
| <type>route</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>locality</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalunya</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>08017</long_name> |
| <short_name>08017</short_name> |
| <type>postal_code</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.4041011</lat> |
| <lng>2.1173659</lng> |
| </location> |
| <location_type>RANGE_INTERPOLATED</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.4027462</lat> |
| <lng>2.1159960</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4054442</lat> |
| <lng>2.1186939</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.4040589</lat> |
| <lng>2.1172802</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4041315</lat> |
| <lng>2.1174097</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>EjJDYXJyZXIgZCdJc2FhYyBBbGLDqW5peiwgMSwgMDgwMTcgQmFyY2Vsb25hLCBTcGFpbg</place_id>|
| </result> |
| <result> |
| <type>bus_station</type> |
| <type>establishment</type> |
| <type>point_of_interest</type> |
| <type>transit_station</type> |
| <formatted_address>Pl. Borràs, 08017 Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>Pl. Borràs</long_name> |
| <short_name>Pl. Borràs</short_name> |
| <type>establishment</type> |
| <type>point_of_interest</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>locality</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalunya</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>08017</long_name> |
| <short_name>08017</short_name> |
| <type>postal_code</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.4040000</lat> |
| <lng>2.1172210</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.4026510</lat> |
| <lng>2.1158720</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4053490</lat> |
| <lng>2.1185700</lng> |
| </northeast> |
| </viewport> |
| </geometry> |
| <place_id>ChIJR9mCTjiYpBIRY_wBnYXCVt0</place_id> |
| </result> |
| <result> |
| <type>neighborhood</type> |
| <type>political</type> |
| <formatted_address>Sarrià, Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>Sarrià</long_name> |
| <short_name>Sarrià</short_name> |
| <type>neighborhood</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Sarrià-Sant Gervasi</long_name> |
| <short_name>Sarrià-Sant Gervasi</short_name> |
| <type>political</type> |
| <type>sublocality</type> |
| <type>sublocality_level_1</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>locality</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>El Barcelonès</long_name> |
| <short_name>El Barcelonès</short_name> |
| <type>administrative_area_level_3</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.3969043</lat> |
| <lng>2.1203894</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.3901309</lat> |
| <lng>2.1032100</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4141199</lat> |
| <lng>2.1299878</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.3901309</lat> |
| <lng>2.1032100</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4141199</lat> |
| <lng>2.1299878</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJr9XzmjmYpBIR0vSCQOH6ACY</place_id> |
| </result> |
| <result> |
| <type>political</type> |
| <type>sublocality</type> |
| <type>sublocality_level_1</type> |
| <formatted_address>Sarrià-Sant Gervasi, Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>Sarrià-Sant Gervasi</long_name> |
| <short_name>Sarrià-Sant Gervasi</short_name> |
| <type>political</type> |
| <type>sublocality</type> |
| <type>sublocality_level_1</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>locality</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>El Barcelonès</long_name> |
| <short_name>El Barcelonès</short_name> |
| <type>administrative_area_level_3</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.3993167</lat> |
| <lng>2.1341754</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.3901309</lat> |
| <lng>2.0695258</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4370448</lat> |
| <lng>2.1555601</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.3901309</lat> |
| <lng>2.0695258</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4370448</lat> |
| <lng>2.1555601</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJPZtvTy6YpBIR2Rr7VSOwe3Q</place_id> |
| </result> |
| <result> |
| <type>locality</type> |
| <type>political</type> |
| <formatted_address>Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>locality</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_4</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>El Barcelonès</long_name> |
| <short_name>El Barcelonès</short_name> |
| <type>administrative_area_level_3</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.3850639</lat> |
| <lng>2.1734035</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.3200040</lat> |
| <lng>2.0695257</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4695760</lat> |
| <lng>2.2280099</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.3200040</lat> |
| <lng>2.0695257</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4695760</lat> |
| <lng>2.2280099</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJ5TCOcRaYpBIRCmZHTz37sEQ</place_id> |
| </result> |
| <result> |
| <type>postal_code</type> |
| <formatted_address>08017 Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>08017</long_name> |
| <short_name>08017</short_name> |
| <type>postal_code</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>locality</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.4171333</lat> |
| <lng>2.1008486</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.3878888</lat> |
| <lng>2.0702927</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4371640</lat> |
| <lng>2.1396189</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.3878888</lat> |
| <lng>2.0702927</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4371640</lat> |
| <lng>2.1396189</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJZW4qodqZpBIR0ExHeuP6ABw</place_id> |
| </result> |
| <result> |
| <type>administrative_area_level_4</type> |
| <type>political</type> |
| <formatted_address>Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_4</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>El Barcelonès</long_name> |
| <short_name>El Barcelonès</short_name> |
| <type>administrative_area_level_3</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.3850494</lat> |
| <lng>2.1733247</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.3200040</lat> |
| <lng>2.0524976</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4679427</lat> |
| <lng>2.2280099</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.3200040</lat> |
| <lng>2.0524976</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4679427</lat> |
| <lng>2.2280099</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJ9SjtJnGYpBIRMAOkIeD6AAQ</place_id> |
| </result> |
| <result> |
| <type>administrative_area_level_3</type> |
| <type>political</type> |
| <formatted_address>El Barcelonès, Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>El Barcelonès</long_name> |
| <short_name>El Barcelonès</short_name> |
| <type>administrative_area_level_3</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalunya</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.4016668</lat> |
| <lng>2.1253854</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.3200453</lat> |
| <lng>2.0529518</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4929026</lat> |
| <lng>2.2705361</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.3200453</lat> |
| <lng>2.0529518</lng> |
| </southwest> |
| <northeast> |
| <lat>41.4929026</lat> |
| <lng>2.2705361</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJcQYdL7mipBIRQ2KtcuxW2Hg</place_id> |
| </result> |
| <result> |
| <type>political</type> |
| <formatted_address>Barcelona Metropolitan Area, Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>Barcelona Metropolitan Area</long_name> |
| <short_name>Barcelona Metropolitan Area</short_name> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.3834010</lat> |
| <lng>2.0273190</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.2636384</lat> |
| <lng>1.8467310</lng> |
| </southwest> |
| <northeast> |
| <lat>41.5749847</lat> |
| <lng>2.2963814</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.2636384</lat> |
| <lng>1.8467310</lng> |
| </southwest> |
| <northeast> |
| <lat>41.5749847</lat> |
| <lng>2.2963814</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJR7wL1XaYpBIR7EoGAtgHJ0Y</place_id> |
| </result> |
| <result> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| <formatted_address>Barcelona, Spain</formatted_address> |
| <address_component> |
| <long_name>Barcelona</long_name> |
| <short_name>Barcelona</short_name> |
| <type>administrative_area_level_2</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.3850477</lat> |
| <lng>2.1733131</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>41.1927451</lat> |
| <lng>1.3596215</lng> |
| </southwest> |
| <northeast> |
| <lat>42.3233011</lat> |
| <lng>2.7777843</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>41.1927451</lat> |
| <lng>1.3596215</lng> |
| </southwest> |
| <northeast> |
| <lat>42.3233011</lat> |
| <lng>2.7777843</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJZb1_yQvmpBIRsMmjIeD6AAM</place_id> |
| </result> |
| <result> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| <formatted_address>Catalonia, Spain</formatted_address> |
| <address_component> |
| <long_name>Catalonia</long_name> |
| <short_name>CT</short_name> |
| <type>administrative_area_level_1</type> |
| <type>political</type> |
| </address_component> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>41.5911589</lat> |
| <lng>1.5208624</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>40.5230527</lat> |
| <lng>0.1591811</lng> |
| </southwest> |
| <northeast> |
| <lat>42.8614502</lat> |
| <lng>3.3325444</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>40.5230527</lat> |
| <lng>0.1591811</lng> |
| </southwest> |
| <northeast> |
| <lat>42.8614502</lat> |
| <lng>3.3325444</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJ8_UwhdxbpBIRUMijIeD6AAE</place_id> |
| </result> |
| <result> |
| <type>country</type> |
| <type>political</type> |
| <formatted_address>Spain</formatted_address> |
| <address_component> |
| <long_name>Spain</long_name> |
| <short_name>ES</short_name> |
| <type>country</type> |
| <type>political</type> |
| </address_component> |
| <geometry> |
| <location> |
| <lat>40.4636670</lat> |
| <lng>-3.7492200</lng> |
| </location> |
| <location_type>APPROXIMATE</location_type> |
| <viewport> |
| <southwest> |
| <lat>35.1730000</lat> |
| <lng>-12.5240000</lng> |
| </southwest> |
| <northeast> |
| <lat>45.2440000</lat> |
| <lng>5.0980000</lng> |
| </northeast> |
| </viewport> |
| <bounds> |
| <southwest> |
| <lat>27.6378936</lat> |
| <lng>-18.1607880</lng> |
| </southwest> |
| <northeast> |
| <lat>43.7913218</lat> |
| <lng>4.3277839</lng> |
| </northeast> |
| </bounds> |
| </geometry> |
| <place_id>ChIJi7xhMnjjQgwR7KNoB5Qs7KY</place_id> |
| </result> |
|</GeocodeResponse> |
| |
+---------------------------------------------------------------------------------------------+