Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geofence #131

Open
ewooonk opened this issue Nov 28, 2017 · 2 comments
Open

Geofence #131

ewooonk opened this issue Nov 28, 2017 · 2 comments

Comments

@ewooonk
Copy link

ewooonk commented Nov 28, 2017

Only allow the user to rent / return a bike if they are within x meters of the stand.

@ewooonk
Copy link
Author

ewooonk commented Nov 29, 2017

The following code can be used to calculate the distance (in km) between the user and the stand in functions.js. Next step: implementing in rent() function.

latdif = Math.abs($("body").data("mapcenterlat")-lat); 
longdif = Math.abs($("body").data("mapcenterlong")-long);
latdifkm = latdif*111;
longdifkm = longdif*111*Math.cos(lat*Math.PI/180);
difkm = Math.sqrt((latdifkm*latdifkm)+(longdifkm*longdifkm));

@ewooonk ewooonk closed this as completed Nov 29, 2017
@ewooonk ewooonk reopened this Nov 30, 2017
@ewooonk
Copy link
Author

ewooonk commented Nov 30, 2017

Full implementation of the geofence.

functions.js

showlocation, changelocation
Change the radius of the circle displayed on the map to 200m.
circle = L.circle([$("body").data("mapcenterlat"), $("body").data("mapcenterlong")],40*5, {

showstand
Add:

latdif = Math.abs($("body").data("mapcenterlat")-lat);
longdif = Math.abs($("body").data("mapcenterlong")-long);
latdifkm = latdif*111;
longdifkm = longdif*111*Math.cos(lat*Math.PI/180);
difkm = Math.sqrt((latdifkm*latdifkm)+(longdifkm*longdifkm));

rent

Add:

   geofenceid=1;
   if (difkm < 0.2) geofenceid=2;

Replace:

url: "command.php?action=rent&bikeno="+$('#rent .bikenumber').html()+"&geofence="+geofenceid

returnbike

Add:

   geofenceid=1;
   if (difkm < 0.2) geofenceid=2;

Replace:

url: "command.php?action=return&bikeno="+$('#return .bikenumber').html()+"&stand="+standname+note+"&geofence="+geofenceid

command.php

Replace

   case "rent":
      logrequest($userid,$action);
      checksession();
      $bikeno=trim($_GET["bikeno"]);
      $geofenceid=trim($_GET["geofence"]);
      checkbikeno($bikeno);
      rent($userid,$bikeno,$geofenceid);
      break;
   case "return":
      logrequest($userid,$action);
      checksession();
      $bikeno=trim($_GET["bikeno"]);
      $stand=trim($_GET["stand"]);
      $geofenceid=trim($_GET["geofence"]);
      $note="";
      if (isset($_GET["note"])) $note=trim($_GET["note"]);
      checkbikeno($bikeno); checkstandname($stand);
      returnBike($userid,$bikeno,$stand,$note,$geofenceid);
      break;

Replace:

   case "forcerent":
      logrequest($userid,$action);
      checksession();
      checkprivileges($userid);
      $bikeno=trim($_GET["bikeno"]);
      checkbikeno($bikeno);
      rent($userid,$bikeno,$geofence,TRUE);
      break;
   case "forcereturn":
      logrequest($userid,$action);
      checksession();
      checkprivileges($userid);
      $bikeno=trim($_GET["bikeno"]);
      $stand=trim($_GET["stand"]);
      $note="";
      if (isset($_GET["note"])) $note=trim($_GET["note"]);
      checkbikeno($bikeno); checkstandname($stand);
      returnBike($userid,$bikeno,$stand,$note,$geofenceid,TRUE);
      break;

actions-web.php

rent

Replace

function rent($userId,$bike,$geofenceidd,$force=FALSE)

Add the following to if ($force==FALSE)

      if ($geofenceidd==1)
         {
         response(_('You are outside the geofence.')." "._('Please, enable GPS location services or choose a nearby stand.'),ERROR);
         }

returnBike

Replace

'function returnBike($userId,$bike,$stand,$note="",$geofenceidd,$force=FALSE)'

Add the following to if ($force==FALSE)

      if ($geofenceidd==1)
         {
         response(_('You are outside the geofence.')." "._('Please, enable GPS location services or choose a nearby stand.'),ERROR);
         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants