Skip to content

FamilyTree getLocationJSON.php

James Cobban edited this page Apr 26, 2020 · 3 revisions

Up: Family Tree Implementation

This script is invoked from JavaScript, in particular the Location services function locationChanged to search the database for instances of class Location that match a request. It returns a JavaScript Object Notation (JSON) document containing the content of the matching object[s].

This script is invoked with parameters which are use to restrict the response. If no parameters are specified it returns the first 40 entries in the table of Locations.

Parameters (passed by method='GET'):

parameter description
'limit' specify the maximum number of records to return, default 40
'name' specifies to search for Locations whose location name starts with the specified string or whose short name is an exact match.
'idlr' identifies a specific instance of Location by its internal numeric key
'fsplaceid' LDS FamilySearch place id
'location' location name pattern. This is a regular expression. For example a simple string matches all Locations whose name contains the specified string.
'sortedlocation' pattern match to the sort key used when displaying a list of locations
'latitude' latitude
'longitude' longitude
'shortname' pattern match to the short name
'preposition' preposition used before the location. The empty string displays "at".
'notes' pattern match to notes
'zoom' map zoom level, an integer
'boundary' boundary, a comma list of longitude and latitude values

For example a request specifying 'location' 'London' returns:

    "parms" : {
        "name" : "london"
    },
    "count" : "1",
    "cmd" : "SELECT * FROM tblLR WHERE (`location`='london' OR `shortname`='london') ORDER BY SortedLocation, IDLR LIMIT 40",
    "locations" : {
    
    "1" :
       {
	"idlr":	        2825,
	"fsplaceid":	"",
	"preposition":	"",
	"location":	"London, ON, CA",
	"sortedlocation":	"London, ON, CA",
	"shortname":	"London",
	"tag1":	        1,
	"used":	        1,
	"notes":	"Largest city in south-west Ontario, located at the fork of the River Thames.<br \/>",
	"verified":	0,
	"latitude":	425845.9984000000,
	"longitude":	-811445.9996000000,
	"fsresolved":	0,
	"veresolved":	0,
	"qstag":	0,
	"zoom":	        11,
	"boundary":	""
        }
    }
}

This information is also available with slightly different parameters and results using getRecordJson.php.

To avoid annoying users with unhelpful error messages if the 'location' parameter does not match an existing Location but is almost certainly valid, if the 'location' starts with a number or 'lot ' followed by a number, where a number is a sequence of the digits 0 through 9 plus '½', then the script looks for instances of Location which end with the same street name or concession identifier. If there are any then the script returns as if the requested location does exist, except that the value of response.locations[1].idlr is 0 and response.cmd shows the search for the trailing part of the location name.

    "parms" : {
        "name" : "156½ king st, london, ON, CA"
    },
    "count" : "1",
    "cmd" : "SELECT * FROM tblLR WHERE RIGHT(`location`, 23)='king st, london, ON, CA' ORDER BY SortedLocation, IDLR LIMIT 40",
    "locations" : {
    
    "1" :
       {
	"idlr":	0,
	"fsplaceid":	"",
	"location":	"156\u00bd king st, london, ON, CA",
	"used":	0,
	"sortedlocation":	"king st, london, ON, CA, 156\u00bd",
	"latitude":	0,
	"longitude":	0,
	"tag1":	0,
	"shortname":	"156\u00bd king st, london, ON, CA",
	"preposition":	"",
	"notes":	"",
	"verified":	0,
	"fsresolved":	0,
	"veresolved":	0,
	"qstag":	0,
	"zoom":	15,
	"boundary":	""
       }

    }
}

Next: FamilyTree getLocationXml.php

Clone this wiki locally