jay wrote:chrisla23 wrote:I wrote a script to get the GPS location of a cellphone from Instamapper
http://www.instamapper.com/ , lookup the location with geoNames,
http://www.geonames.org/ and update Indigo with the location.
The script will be updated into the user contribution library.
-Chris
Approved - thanks for the script!
A couple of notes:
1) It doesn't seem to find any street close to me, which doesn't really surprise me (I'm kinda out of town) - you might consider entering an "Unknown Location" in when locationText ends up empty.
2) It would also be nice if you stored the raw lon/lat values in a different set of variables - then someone could do a little math with the lon/lat that's configured in Indigo (and are available to AppleScripts through properties of the application object) to see how close the device is.
Again, thanks for the contribution!
Actually, there appears to be a bug in the script when a location isn't found. You get the following XML in the file returned from geonames:
- Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames/>
when it doesn't find a match to the location passed in. When this line of the script is executed:
- Code: Select all
set locationText to (value of XML element "placename")
It throws an error (-1728 - System Events got an error: Can’t get XML element "streetSegment" of XML element "geonames" of contents of XML file "tmp:xmlfile.xml") which, since you don't have an "on error" handler in the try block, just skips setting the variable altogether. I'd suggest putting the tell to "IndigoServer" outside the try block, then add an "on error" section that sets locationText to "Unknown Location" or something if an error is encountered - but there are other things you could do there as well.