php - Passbook - Hardcoding locations in JSON works but not passing variable -


i using pre-built structure found here create apple passbook passes. i'm using starbucks example different parameters.

background: apple allows 10 locations saved pass. purpose of saving locations triggers phone notification when near.

the flow of system is:

  • user inputs home address
  • google retrieves exact coordinates lat/lng
  • lat , lng set form's hidden inputs , posted pass creation php.
  • server queries 10 nearest locations , adds positions pass json.
  • pass creates , downloads

problem

it's possible it's problem php or passbook.

posted variables query in mysql fine. in testing json, json matches target pattern given in documentation exampled below. 10 nearest stores indeed insert in correct syntax. however, passes had locations hardcoded in json

    'locations' => array(          array(             'longitude' => 123456,             'latitude' => 123456,             'relevanttext' => 'you near store'             )         ) 

these show in map locations.

passes had locations set variables in way, such as

    'locations' => array(          array(             'longitude' => $lng,             'latitude' => $lat,             'relevanttext' => 'you near store'             )         ) 

does not show locations on map. have tried mixing both approaches, , sure enough, hardcoded locations show - variable-submitted lats , lngs ignored.

right before final pass creation step, location formula like:

"locations":[ {"longitude":-xx.xxxx,"latitude":xx.xxxx,"relevanttext":"place name"}, ...(ten times.. comma'd until last one)... ] 

which can compared target formula in apple's documentation:

"locations" : [     {"latitude" : 37.3229, "longitude" : -122.0323, "relevanttext" : "store nearby on 3rd , main."} ] 

i don't understand why variables can passed fine, query fine, enter json fine, make distinction in pass file does.


edit: more information on request. html form on index passes lat/lng given google geocode.

<form action="pass.php" method="post">            <fieldset>                <input type='text' id='lat' name='lat' value='' > //set thru jquery         <input type='text' id='lng' name='lng' value='' > //set thru jquery               <input type="submit" class="btn primary" name='pass' id='passbutton' value=" create pass &gt; " disabled />         </fieldset> </form> 

the pass.php generates pass:

<?php require('pkpass/pkpass.php');  $lat = floatval($_post['lat']); $lng = floatval($_post['lng']);  require_once ('../../functions.php'); //get mysql wrapper class   $query = "select *, ( 3959 * acos( cos( radians($lat) ) * cos( radians( latitude ) ) *  cos( radians( longitude ) - radians($lng) ) + sin( radians($lat) ) *  sin( radians( latitude ) ) ) ) distance dealers having distance < 25 order distance limit 0 , 10;";  $result = $db->doquery($query); //wrapper class helps queries $pass = new pkpass\pkpass();   $pass->setcertificate('cert/pass.p12'); $pass->setcertificatepassword('password'); $pass->setwwdrcertpath('cert/applewwdrca.pem');  // top-level keys  $standardkeys         = array(     'description'        => 'demo pass',     'formatversion'      => 1,     'organizationname'   => 'name',     'passtypeidentifier' => 'pass.place.coupon',     'serialnumber'       => '123456',     'teamidentifier'     => 'identifier' ); $associatedappkeys    = array(); $relevancekeys        = array(     'locations' => array(      )    );  while ($row = $result->fetch_object()) {      $array =              array(          'longitude' => sprintf("%.4f", floatval($row->longitude)),          'latitude' => sprintf("%.4f",floatval($row->latitude)),         'relevanttext' => $row->name    );      $relevancekeys['locations'][] = $array;  }   $stylekeys            = array(      'coupon' => array(     'primaryfields' => array(       array(         'key' => 'offer',         'label' => 'item',         'value' => 'free'       )     ),      'auxiliaryfields' => array(       array(         'key' => 'expires',         'label' => 'expires',         'value' => '2018-04-24t10:00-05:00',         'isrelative' => true,         'datestyle' => 'pkdatestyleshort'       )     )   ) );  $visualappearancekeys = array(     'barcode'         => array(         'format'          => 'pkbarcodeformatpdf417', //        'format'          => 'pkbarcodeformatqr',         'message'         => 'message',         'messageencoding' => 'iso-8859-1'     ), //    'foregroundcolor' => 'rgb(255, 255, 255)',     'backgroundcolor' => 'rgb(39,81,154)',     'logotext'        => 'company' ); $webservicekeys       = array();  // merge pass data , set json $pass object $passdata = array_merge(     $standardkeys,     $associatedappkeys,     $relevancekeys,     $stylekeys,     $visualappearancekeys,     $webservicekeys );  $pass->setjson(json_encode($passdata));  // add files pkpass package $pass->addfile('icon.png'); $pass->addfile('icon@2x.png'); $pass->addfile('logo.png');  if(!$pass->create(true)) { // create , output pkpass     echo 'error: '.$pass->geterror(); } 

obvious things in caps omissions.

resulting json:

        {"description":"demo pass","formatversion":1,"organizationname":"name","passtypeidentifier":"pass.place.coupon","serialnumber":"123456","teamidentifier":"identifier","locations":[{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_1"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_2"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_3"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_4"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_5"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_6"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_7"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_8"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_9"},{"longitude":"-xx.xxxx","latitude":"xx.xxxx","relevanttext":"store_10"}],"coupon":{"primaryfields":[{"key":"offer","label":"item","value":"free"}],"auxiliaryfields":[{"key":"expires","label":"expires","value":"2018-04-24t10:00-05:00","isrelative":true,"datestyle":"pkdatestyleshort"}]},"barcode":{"format":"pkbarcodeformatpdf417","message":"message","messageencoding":"iso-8859-1"},"backgroundcolor":"rgb(39,81,154)","logotext":"company"} 

obviously, xx.xxxx values being real numbers. fact strings or numbers not seem have mattered. when hardcoded them, strings. above json not make pass file map locations, when if lat/lng hardcoded. tested on passwallet, works. on io6 simulator, says "safari cannot download file." when have gotten use passes before.

with additional information, problem clear.

the fact strings or numbers not seem have mattered.

actually passbook matter. passbook meticulously picky on type. sprintf("%.4f", floatval($row->longitude)) casting query results strings, package format requires double.

from passbook package format reference:

enter image description here

no need format particular number of places, throw in raw float values , should fine.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

gradle error "Cannot convert the provided notation to a File or URI" -