1

I want to use many locations to show on lock screen. I tested already, only 10 locations is shown. Are there any way to show more than 10 locations ?

malinchhan
  • 767
  • 2
  • 8
  • 28

1 Answers1

1

Rachel is correct in that Passbook will only recognise the first 10 locations included in pass.json. If there are any more than 10, then these will be ignored.

The workaround that you link to, proposes the following:

  • You create a location enabled app
  • Whenever your app detects a significant location change, it signals your server, providing the pass serial number and the new location
  • Your server then selects the 10 closest locations, compiles a new pass and pushes it to the device

Depending on how sophisticated you want to get in determining the most appropriate locations, it could be a bit of work. It also doesn't make for a great user experience since the location will eat battery and the constant updating of the pass will eat data.

Three alternative approaches are:

  • Letting the user select the 10 most appropriate locations for them, or
  • Updating the locations whenever the pass is used. If the pass is scanned, then you can use the location of the scanning device to determine the 10 closest locations and push an updated pass, or
  • Adding a unique link on the back of the pass to a HTML5 page that grabs their current location with Javascript (see below), then initiates a push. E.g. To update you pass with the 10 nearest locations, click the link below http://www.yourservice.com/?passSerial=xxxx

Sample location JS:

<script>
if(navigator.geolocation){
    navigator.geolocation.getCurrentPosition(success,fail);
}

function success(a) {            
    $("#long").val(a.coords.longitude).focus(); // focus required to force an update of the field value in webkit browsers
    $("#lat").val(a.coords.latitude).focus();
    // initiate ajax callback to push new pass and alert the user that it is on the way

}
function fail() {
    alert("You must give permission to provide your location, please refresh this page and try again");
}
</script>
PassKit
  • 12,231
  • 5
  • 57
  • 75
  • Thank you, PassKit ! I will try to do this! I only have 2 days to solve this problem ! – malinchhan May 21 '13 at 10:31
  • your alternative approaches are interesting ! I will try it ! – malinchhan May 22 '13 at 01:40
  • How to find 10 closest locations ? – malinchhan May 22 '13 at 02:00
  • If pass is not used, can I detect 10 closest locations ? – malinchhan May 22 '13 at 02:37
  • in my database, I store longitude and latitude as double ! – malinchhan May 22 '13 at 04:23
  • I try this: set @orig_lat=122.4058; set @orig_lon=37.7907;set @dist=10; SELECT *,3956 * 2 * ASIN(SQRT( POWER(SIN((@orig_lat - abs( dest.latitude)) * pi()/180 / 2),2) + COS(@orig_lat * pi()/180 ) * COS( abs (dest.latitude) * pi()/180) * POWER(SIN((@orig_lon – dest.longtitude) * pi()/180 / 2), 2) )) as distance FROM company dest where distance < @dist ORDER BY distance limit 10; – malinchhan May 22 '13 at 04:49
  • #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '– dest.longtitude) * pi()/180 / 2), 2) )) as distance FROM company dest w' at line 5 – malinchhan May 22 '13 at 06:27
  • `longtitude` is not spelt correctly what happens if you change to `dest.longitude`? – PassKit May 22 '13 at 07:07
  • still error even I change: SELECT *,3956 * 2 * ASIN(SQRT( POWER(SIN((122.4058 - abs( dest.latitude)) * pi()/180 / 2),2) + COS(122.4058 * pi()/180 ) * COS( abs (dest.latitude) * pi()/180) * POWER(SIN((37.7907 – dest.longitude) * pi()/180 / 2), 2) )) as distance FROM company as dest where distance < 10 ORDER BY distance limit 10; – malinchhan May 22 '13 at 09:04
  • error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '– dest.longitude) * pi()/180 / 2), 2) )) as distance FROM company as dest wher' at line 1 – malinchhan May 22 '13 at 09:05
  • It might be clearer if you post as a separate question and tag it with MYSQL – PassKit May 22 '13 at 09:12
  • And also double check your column name for longitude to make sure it matches your query. – PassKit May 22 '13 at 09:14
  • When I use this query: SELECT *,3956 * 2 * ASIN(SQRT( POWER(SIN((122.4058 - abs(dest.latitude)) * pi()/180 / 2),2) + COS(122.4058 * pi()/180 ) * COS( abs(dest.latitude) * pi()/180) * POWER(SIN((37.7907 - abs(dest.longitude)) * pi()/180 / 2), 2) )) as dis FROM company as dest where dest.longitude is not null and dest.latitude is not null ORDER BY dis limit 10; – malinchhan May 23 '13 at 02:14
  • it shows 10 rows, but it's not correct for all ! I put number 1 to 10 that is closest but it shows in random companyID such as : 14, 4, 18,1, 20,9,10,2, 15,21 – malinchhan May 23 '13 at 02:17
  • what should I add more to select closest locations ! – malinchhan May 23 '13 at 02:19
  • I think that [this is the presentation](http://www.arubin.org/files/geo_search.pdf) where the formula you are using originated from. You have hardcoded values for orig.latitude and orig.longitude. The orig.latitude you have entered also appears to be invalid (>90). What happens if you replace these values with the lat / lng of the centre point you want to search around? – PassKit May 23 '13 at 03:03
  • yes, I follow the formular in that link. what is lat/long of center point ? – malinchhan May 23 '13 at 03:16
  • The lat/long of the point that you want to get the 10 nearest locations to – PassKit May 23 '13 at 03:24
  • Can I use current location of user as center point ? and can it changeable ? as the users will be in different places, so I need to select 10 locations that are nearest to them. – malinchhan May 23 '13 at 03:30
  • even I use current lat/long, I still get result like before. I use this query: SELECT *,3956 * 2 * ASIN(SQRT( POWER(SIN((104.89529371261597 - abs(dest.latitude)) * pi()/180 / 2),2) + COS(104.89529371261597 * pi()/180 ) * COS( abs(dest.latitude) * pi()/180) * POWER(SIN((11.576150037278605 - dest.longitude) * pi()/180 / 2), 2) )) as dis FROM company dest where dest.longitude is not null and dest.latitude is not null ORDER BY dis limit 10; – malinchhan May 23 '13 at 04:04
  • now I can get the nearest places to my current locations by using this query: SELECT companyID,relevantTextName as companyName, ACOS( SIN( RADIANS( dest.latitude ) ) * SIN( RADIANS( 11.576150037278605 ) ) + COS( RADIANS( dest.latitude ) ) * COS( RADIANS( 11.576150037278605 )) * COS( RADIANS( dest.longitude ) - RADIANS( 104.89529371261597 )) ) * 6380 AS distance FROM company as dest having distance < 10 ORDER BY distance limit 10; – malinchhan May 23 '13 at 04:24
  • You have your lat and lng the wrong way around. Try ` SELECT *,3956 * 2 * ASIN(SQRT( POWER(SIN((11.576150037278605 - abs(dest.latitude)) * pi()/180 / 2),2) + COS(11.576150037278605 * pi()/180 ) * COS( abs(dest.latitude) * pi()/180) * POWER(SIN((104.89529371261597 - dest.longitude) * pi()/180 / 2), 2) )) as dis FROM company dest where dest.longitude is not null and dest.latitude is not null ORDER BY dis limit 10; ` – PassKit May 23 '13 at 04:25
  • And yes - it would make sense to use the current location of the device once you have tested that your query works. – PassKit May 23 '13 at 04:27
  • Just thought of another alternative using javascript - much easier and user-friendly to implement than an app, see updated answer. – PassKit May 23 '13 at 04:40
  • But can I update pass automatically without any notice of user ? because users may not click link at the back of pass. – malinchhan May 23 '13 at 05:37
  • True - they would need to click the back of the pass, but this is much more likely to happen than them downloading your app and keeping it running, consuming battery. Especially if the only purpose of the app is to provide location updates. Of course you could always do both. – PassKit May 23 '13 at 05:43
  • I could do both ? what are they ? – malinchhan May 23 '13 at 06:03
  • I want to find the way that user don't do any thing but server has to update the locations when user move the new place ! – malinchhan May 23 '13 at 06:07
  • You can only automate that with an app, but the users may not download your app, or may not authorise location updates, or may not launch it after a reboot - so in reality there is no sure way to automatically update the pass. For both, I meant that you could have an app, but also offer a link on the back of the pass for the user to manually update their locations if they move to a new location. You also could implement the third option of pushing an update with new locations whenever the pass is used. – PassKit May 23 '13 at 06:39
  • to get current location lat/long, can I use php ? – malinchhan May 23 '13 at 07:50
  • The above code assumes that you are using jQuery, and have type input fields (most likely hidden) with the ids "long" and "lat" E.g. `` When the page loads, navigator will automatically prompt the user for permission to use their location. If permission is given the code will automatically update these field values. – PassKit May 23 '13 at 08:01
  • Look at the source for [this page](http://passkit.com/geo) - it grabs the lat / long and populates a form. – PassKit May 23 '13 at 10:48
  • What don't you understand? – PassKit May 24 '13 at 02:11
  • where is your script for location ? You have file js and jquery with a lot of code. – malinchhan May 24 '13 at 02:42
  • [This one should be simpler](http://pastebin.com/6zP8TsLn), not tested - it contains the same code as above. – PassKit May 24 '13 at 02:47
  • Yes, I got it ! it's more easier to understand ! Thank you !! – malinchhan May 24 '13 at 02:55
  • so I have to use : ? – malinchhan May 24 '13 at 02:58
  • before u use : jquery-1.8.0.min.js – malinchhan May 24 '13 at 03:03
  • Doesn't matter which version of jQuery, jQuery 2.0.0 is the latest version - doesn't work with IE 6,7 & 8 but that will not be an issue for iOS clients – PassKit May 24 '13 at 03:07
  • but my company not yet accept this solution because users don't have interaction with this pass ! – malinchhan May 24 '13 at 03:13
  • I have to find solution that make user easier ! – malinchhan May 24 '13 at 03:14
  • I'm not sure that there is one that works within the constraints of the PassKit framework unless you add an app which kind of defeats the whole point of Passbook. – PassKit May 24 '13 at 03:18
  • what that means ? I have to make an app that can contact with passbook ? – malinchhan May 24 '13 at 03:47
  • To be able to update the pass with new locations, then you need to know the location of the user and trigger a push. Passbook does not provide location information back to the Pass issuer, which means that you need to get the location from somewhere else. This leaves you 3 options: 1. a companion app that constantly monitors location and reports back to your server whenever there is a significant change so that you can push a new pass;2. whenever the pass is used, take the location of the scan and use it to push a new pass with updated locations;or 3. allow the user to provide their location – PassKit May 24 '13 at 04:15
  • yes, I will try 1 among them ! first option is interesting. what a companion app do ? Could you explain more ? – malinchhan May 24 '13 at 07:05
  • I though that is what you were creating? A companion app would check to see if the pass is installed an would know what locations were in the pass. If the user changes location, the app can detect the location change, then call your web service to either: trigger a push to update the pass with new locations; or silently retrieve a .pkpass bundle from your web service and use the replacePassWithPass method of the PassKit framework to replace the pass in the user's Passbook. – PassKit May 24 '13 at 09:17
  • For the test of current lat/lng before, can it show lat/lng directly without clicking in textField ? – malinchhan May 24 '13 at 10:16
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30552/discussion-between-passkit-and-smallgirl) – PassKit May 24 '13 at 10:17
  • I want to use it as method by return lat/lng, so I test :
    – malinchhan May 24 '13 at 10:17
  • Instead of serialising the form `$("#locationForm").serialize()`, how about creating a custom dictionary `{ "long" : a.coords.longitude, "lat" : a.coords.latitude, "serial" : ""}` – PassKit May 24 '13 at 10:27
  • How to use this custom dictionary ? – malinchhan May 27 '13 at 01:29
  • This dictionary represents what is posted to your server. You said you had problems with the field values not being filled so instead of serialising and posting the form content, you can try posting the values directly. – PassKit May 27 '13 at 02:34
  • When I test your code to find current lat/lng, lat/lng appear when I click in texField. So, if I don't click it, is there other ways to show it directly ? – malinchhan May 27 '13 at 04:48
  • See updated answer - adding `.focus()` will simulate the click in the text field to display the value. – PassKit May 27 '13 at 06:01