简体   繁体   中英

How To Add A Blacklist to Location

I am working on something to blacklist unwanted locations with the location service. Here is my current code:

How can I implement a blacklist feature?

  if (navigator.geolocation) { // Locate position navigator.geolocation.getCurrentPosition(displayPosition, errorFunction); } else { alert('Your device location is not approved.'); } // Success callback function function displayPosition(pos) { var mylat = pos.coords.latitude; var mylong = pos.coords.longitude; var thediv = document.getElementById('locationinfo'); alert('Your HWID is compliant of ProtoProt regulations.'); } function errorFunction(pos) { alert('Error: (PROTOPROT_POS_DENIED). We only use your HWID for checking compliance. Enable location to enter.'); } 

Maintain a list of locations given by two points w,y.

Each w,y represent the two opposite points of aw,x,y,z square which represents the blacklisted location.

Each point has longitude and latitude coordinates, so w = [long, lat] and y = [long, lat]

With those, you can rebuild all the [long, lat] of all the w,x,y,z corners of your square, thus representing the blacklisted area.

Now, it's rather easy to know the boundaries of forbidden location: any point [long, lat] which is within the square is blacklisted.

You can store those values within a Javascript Object (a dictionary) which can be stored in a distinct ".js" file. JSON representation could look like:

blacklisted_areas = {
  'area 51' : [w, y], // Replace w y with the floats of long and lat
  'pink unicorn zoo' : [w, y], // same
  // etc.
};

Access:

long = blacklisted_area['area 51'][0]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM