Function GetGeoData(sSearch as String) as String If Len(sSearch) = 0 Then Exit Function 'we dont need empty cells <img draggable="false" class="emoji" alt="
" src="http://s.w.org/images/core/emoji/72x72/1f609.png"> URL = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=true&address=" 'we will use the google maps api URL = URL & sSearch 'create the searchstring oSimpleFileAccess = createUnoService( "com.sun.star.ucb.SimpleFileAccess" ) 'this is the Sefvice in getting the data from the web On Error GoTo ErrorResponse oInputStream = oSimpleFileAccess.openFileRead(URL) 'use the URL oTextStream = createUnoService("com.sun.star.io.TextInputStream") 'get the data from the web oTextStream.InputStream = oInputStream 'this is the data aDelimiters = Array(ASC(">"),ASC("<")) 'as the stream is segmented with ">" and "<" sLastString = "" Do While NOT oTextStream.isEOF 'go through the google output sThisString = oTextStream.readString(aDelimiters,True) Select Case sLastString 'now search for the entries Case "lat": 'latitudes sLat = sThisString Case "lng": 'longitude sLon = sThisString End Select sLastString = sThisString Loop GetGeoData = " Longitude: " & sLon & " Latitude: " &sLat 'this is our output in the new cell oInputStream.closeInput() Exit Function ErrorResponse: GetGeoData = "no values found!!!"End Function
As the function has the name GetGeoData just type in a new cell “=GetGeoData(A1)” and off you go with your new coordinates. As the structure is quite simply you can chnage it according to your needs.
But please read the “Google Maps/Google Earth APIs Terms of Service” whether you are allowed to use this service. Additionally note that you can use this service for 2,500 requests per day and most important :”The Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.”
But please read the “Google Maps/Google Earth APIs Terms of Service” whether you are allowed to use this service. Additionally note that you can use this service for 2,500 requests per day and most important :”The Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.”








