jelockwood / pinpoint

A script for finding your Mac
GNU General Public License v3.0
28 stars 5 forks source link

It's working ok, returning co-ordinates, but a blank address. #4

Closed jelockwood closed 5 years ago

jelockwood commented 5 years ago

@ofirgalcon This is a different problem so I have opened a new issue.

Yes I have - it's working ok, returning co-ordinates, but a blank address.

sudo defaults write /Library/Preferences/com.jelockwood.pinpoint.plist YOUR_API_KEY xxxxxx sudo defaults write /Library/Preferences/com.jelockwood.pinpoint.plist USE_ALTITUDE -bool FALSE sudo defaults write /Library/Preferences/com.jelockwood.pinpoint.plist USE_GEOCODE -bool TRUE

/Library/Application\ Support/pinpoint/bin/pinpoint.sh HTTP/2 200 cache-control: no-cache, no-store, max-age=0, must-revalidate pragma: no-cache expires: Mon, 01 Jan 1990 00:00:00 GMT date: Wed, 20 Feb 2019 09:19:34 GMT vary: X-Origin vary: Origin,Accept-Encoding content-type: application/json; charset=UTF-8 x-content-type-options: nosniff x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block server: GSE alt-svc: quic=":443"; ma=2592000; v="44,43,39" accept-ranges: none

{

"location": { "lat": xx.xxxxx, "lng": xx.xxxxx }, "accuracy": 27.0 } Result code = 200 ls_enabled = 1 This is what gets returned

sudo defaults read "/Library/Application Support/pinpoint/location.plist" { Address = ""; Altitude = 0; CurrentStatus = Successful; GoogleMap = "https://www.google.com/maps/place/xxxxxxxxxxx"; "LS_Enabled" = 0; LastLocationRun = "2019-02-20 09:11:35 +0000"; LastRun = "2019-02-20 09:11:35 +0000"; Latitude = "xx.xxxxx"; LatitudeAccuracy = 23; Longitude = "xx.xxxxxx"; LongitudeAccuracy = 23; StaleLocation = No;

Originally posted by @ofirgalcon in https://github.com/jelockwood/pinpoint/issues/3#issuecomment-465491825

jelockwood commented 5 years ago

I have also reproduced this problem.

The use of Google APIs requires linking a billing account as mentioned in my Wiki. If you don't you only get 2 or 3 uses per day. I believe it is still the case that if you do setup a billing account you get a monthly credit equivalent to about 10,000 uses. My initial test has already used up this 'free' daily allowance as I don't have a billing account myself so this is going to take some time to test.

What I can say is that manually running the command as below with the same API key did work so it would seem likely to be something wrong in my code - probably as a result of either a Google change since I wrote it or an Apple change in High Sierra as I originally tested under Sierra.

This works manually in Terminal obviously with the correct API key entered -

curl -s "https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY"

It produces the following result -

{
   "plus_code" : {
      "compound_code" : "P27Q+MC New York, NY, USA",
      "global_code" : "87G8P27Q+MC"
   },
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "279",
               "short_name" : "279",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Bedford Avenue",
               "short_name" : "Bedford Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Kings County",
               "short_name" : "Kings County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "11211",
               "short_name" : "11211",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "279 Bedford Ave, Brooklyn, NY 11211, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.7142484,
               "lng" : -73.9614103
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.71559738029149,
                  "lng" : -73.9600613197085
               },
               "southwest" : {
                  "lat" : 40.71289941970849,
                  "lng" : -73.96275928029151
               }
            }
         },
         "place_id" : "ChIJT2x8Q2BZwokRpBu2jUzX3dE",
         "plus_code" : {
            "compound_code" : "P27Q+MC New York, United States",
            "global_code" : "87G8P27Q+MC"
         },
         "types" : [
            "bakery",
            "cafe",
            "establishment",
            "food",
            "point_of_interest",
            "store"
         ]
      },
      {
         "address_components" : [
            {
               "long_name" : "281",
               "short_name" : "281",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Bedford Avenue",
               "short_name" : "Bedford Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Kings County",
               "short_name" : "Kings County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "11211",
               "short_name" : "11211",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "4230",
               "short_name" : "4230",
               "types" : [ "postal_code_suffix" ]
            }
         ],
         "formatted_address" : "281 Bedford Ave, Brooklyn, NY 11211, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.7142009,
                  "lng" : -73.96120789999999
               },
               "southwest" : {
                  "lat" : 40.7140632,
                  "lng" : -73.9614302
               }
            },
            "location" : {
               "lat" : 40.71412429999999,
               "lng" : -73.96130769999999
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.7154810302915,
                  "lng" : -73.95997006970849
               },
               "southwest" : {
                  "lat" : 40.7127830697085,
                  "lng" : -73.9626680302915
               }
            }
         },
         "place_id" : "ChIJiYRKQWBZwokR10UtO7vMvr0",
         "types" : [ "premise" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "277",
               "short_name" : "277",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Bedford Avenue",
               "short_name" : "Bedford Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Kings County",
               "short_name" : "Kings County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "11211",
               "short_name" : "11211",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "277 Bedford Ave, Brooklyn, NY 11211, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.7142205,
               "lng" : -73.9612903
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.71556948029149,
                  "lng" : -73.95994131970849
               },
               "southwest" : {
                  "lat" : 40.7128715197085,
                  "lng" : -73.9626392802915
               }
            }
         },
         "place_id" : "ChIJd8BlQ2BZwokRAFUEcm_qrcA",
         "plus_code" : {
            "compound_code" : "P27Q+MF New York, United States",
            "global_code" : "87G8P27Q+MF"
         },
         "types" : [ "street_address" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "279",
               "short_name" : "279",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Bedford Avenue",
               "short_name" : "Bedford Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Kings County",
               "short_name" : "Kings County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "11211",
               "short_name" : "11211",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "279 Bedford Ave, Brooklyn, NY 11211, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.7142546,
               "lng" : -73.9614527
            },
            "location_type" : "RANGE_INTERPOLATED",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.71560358029149,
                  "lng" : -73.96010371970848
               },
               "southwest" : {
                  "lat" : 40.71290561970849,
                  "lng" : -73.96280168029151
               }
            }
         },
         "place_id" : "EigyNzkgQmVkZm9yZCBBdmUsIEJyb29rbHluLCBOWSAxMTIxMSwgVVNBIhsSGQoUChIJ8ThWRGBZwokR3E1zUisk3LUQlwI",
         "types" : [ "street_address" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "11211",
               "short_name" : "11211",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "New York",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Brooklyn, NY 11211, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.7280089,
                  "lng" : -73.9207299
               },
               "southwest" : {
                  "lat" : 40.7008331,
                  "lng" : -73.9644697
               }
            },
            "location" : {
               "lat" : 40.7093358,
               "lng" : -73.9565551
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.7280089,
                  "lng" : -73.9207299
               },
               "southwest" : {
                  "lat" : 40.7008331,
                  "lng" : -73.9644697
               }
            }
         },
         "place_id" : "ChIJvbEjlVdZwokR4KapM3WCFRw",
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Kings County",
               "short_name" : "Kings County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Williamsburg, Brooklyn, NY, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.7251773,
                  "lng" : -73.936498
               },
               "southwest" : {
                  "lat" : 40.6979329,
                  "lng" : -73.96984499999999
               }
            },
            "location" : {
               "lat" : 40.7081156,
               "lng" : -73.9570696
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.7251773,
                  "lng" : -73.936498
               },
               "southwest" : {
                  "lat" : 40.6979329,
                  "lng" : -73.96984499999999
               }
            }
         },
         "place_id" : "ChIJQSrBBv1bwokRbNfFHCnyeYI",
         "types" : [ "neighborhood", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Kings County",
               "short_name" : "Kings County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Kings County, Brooklyn, NY, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.739446,
                  "lng" : -73.83336509999999
               },
               "southwest" : {
                  "lat" : 40.551042,
                  "lng" : -74.05663
               }
            },
            "location" : {
               "lat" : 40.6528762,
               "lng" : -73.95949399999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.739446,
                  "lng" : -73.83336509999999
               },
               "southwest" : {
                  "lat" : 40.551042,
                  "lng" : -74.05663
               }
            }
         },
         "place_id" : "ChIJOwE7_GTtwokRs75rhW4_I6M",
         "types" : [ "administrative_area_level_2", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Kings County",
               "short_name" : "Kings County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Brooklyn, NY, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.739446,
                  "lng" : -73.83336509999999
               },
               "southwest" : {
                  "lat" : 40.551042,
                  "lng" : -74.05663
               }
            },
            "location" : {
               "lat" : 40.6781784,
               "lng" : -73.94415789999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.739446,
                  "lng" : -73.83336509999999
               },
               "southwest" : {
                  "lat" : 40.551042,
                  "lng" : -74.05663
               }
            }
         },
         "place_id" : "ChIJCSF8lBZEwokRhngABHRcdoI",
         "types" : [ "political", "sublocality", "sublocality_level_1" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "New York",
               "short_name" : "New York",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "New York, NY, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.9175771,
                  "lng" : -73.70027209999999
               },
               "southwest" : {
                  "lat" : 40.4773991,
                  "lng" : -74.25908989999999
               }
            },
            "location" : {
               "lat" : 40.7127753,
               "lng" : -74.0059728
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.9175771,
                  "lng" : -73.70027209999999
               },
               "southwest" : {
                  "lat" : 40.4773991,
                  "lng" : -74.25908989999999
               }
            }
         },
         "place_id" : "ChIJOwg_06VPwokRYv534QaPC8g",
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "New York, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 45.015865,
                  "lng" : -71.777491
               },
               "southwest" : {
                  "lat" : 40.4773991,
                  "lng" : -79.7625901
               }
            },
            "location" : {
               "lat" : 43.2994285,
               "lng" : -74.21793260000001
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 45.015865,
                  "lng" : -71.777491
               },
               "southwest" : {
                  "lat" : 40.4773991,
                  "lng" : -79.7625901
               }
            }
         },
         "place_id" : "ChIJqaUj8fBLzEwRZ5UY3sHGz90",
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "United States",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 71.5388001,
                  "lng" : -66.885417
               },
               "southwest" : {
                  "lat" : 18.7763,
                  "lng" : 170.5957
               }
            },
            "location" : {
               "lat" : 37.09024,
               "lng" : -95.712891
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 71.5388001,
                  "lng" : -66.885417
               },
               "southwest" : {
                  "lat" : 18.7763,
                  "lng" : 170.5957
               }
            }
         },
         "place_id" : "ChIJCzYy5IS16lQRQrfeQ5K5Oxw",
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}

My current guess is that the format of this XML is slightly different to before and my script is not extracting the address properly from it. As I recall from when I originally wrote it, you often get multiple slightly different addresses returned as a latitude/longitude is not precise enough to identify a single building. My script (was) picking the most suitable one.

I will try again tomorrow to get manually via Terminal results for my real location and then feed them via the same subset of script to 'extract' the address to test my parsing of the results and once I hopefully have found and fixed the error will reply to this issue. As I said it might take a few days.

ofirgalcon commented 5 years ago

The manual link also works for me. I have a 'paid' account and I haven't used up my allowance. Thanks for looking into this!

jelockwood commented 5 years ago

@ofirgalcon Ok, it turned out to be a combination of two things.

First, the installer package post-install script was not setting the default preference to USE_GEOCODE = TRUE and this would prevent it doing reverse geocode lookups to find the address.

Secondly, the code to extract the address had the actual line that does this inside an IF/THEN when it should have been outside the IF/THEN.

A new release of version 3.0.3 has been posted to fix both problems. Please let me know your results.

jelockwood commented 5 years ago

Closing because I had email confirmation it now works.