51Degrees Location Python  4.2

Reverse Geo-Location services for 51Degrees Pipeline

cloud/gettingstarted.py

To run this example, you will need to create a resource key. The resource key is used as shorthand to store the particular set of properties you are interested in as well as any associated license keys that entitle you to increased request limits and/or paid-for properties.

You can create a resource key using the 51Degrees Configurator.

Expected output:

1 What country is at coordinates:-0.9822207999999999, 51.458048?
2 United Kingdom
1 # *********************************************************************
2 # This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 # Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4 # Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5 #
6 # This Original Work is licensed under the European Union Public Licence (EUPL)
7 # v.1.2 and is subject to its terms as set out below.
8 #
9 # If a copy of the EUPL was not distributed with this file, You can obtain
10 # one at https://opensource.org/licenses/EUPL-1.2.
11 #
12 # The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 # amended by the European Commission) shall be deemed incompatible for
14 # the purposes of the Work and the provisions of the compatibility
15 # clause in Article 5 of the EUPL shall not apply.
16 #
17 # If using the Work as, or as part of, a network application, by
18 # including the attribution notice(s) required under Article 5 of the EUPL
19 # in the end user terms of the application under an appropriate heading,
20 # such notice(s) shall fulfill the requirements of that article.
21 # ********************************************************************
22 
23 
24 
34 
35 from fiftyone_location.location_pipelinebuilder import LocationPipelineBuilder
36 
37 # First create the device detection pipeline with the desired settings.
38 
39 # You need to create a resource key at https://configure.51degrees.com
40 # and paste it into the code, replacing !!YOUR_RESOURCE_KEY!! below.
41 
42 resourceKey = "!!YOUR_RESOURCE_KEY!!"
43 
44 if resourceKey == "!!YOUR_RESOURCE_KEY!!":
45  print("""
46  You need to create a resource key at
47  https://configure.51degrees.com and paste it into the code,
48  'replacing !!YOUR_RESOURCE_KEY!!
49  To get a resourcekey with the properties used in this example go to https://configure.51degrees.com/GCrtGh1L
50  """)
51 else:
52 
53  pipeline = LocationPipelineBuilder({"resourceKey": resourceKey}).build()
54 
55  # We create a FlowData object from the pipeline
56  # this is used to add evidence to and then process
57 
58  flowData = pipeline.create_flowdata()
59 
60  # Here we add a longitude and latitude as evidence
61 
62  latitude = "51.458048"
63  longitude = "-0.9822207999999999"
64 
65  flowData.evidence.add("query.51D_Pos_latitude", latitude)
66  flowData.evidence.add("query.51D_Pos_longitude", longitude)
67 
68  # Now we process the FlowData
69 
70  flowData.process()
71 
72  print("What country is at coordinates:" + longitude + ", " + latitude + "?")
73  if flowData.location.country.has_value():
74  print(flowData.location.country.value())
75  else:
76  print(flowData.location.no_value_message())