dataFields holding only one long value in AltBeacon - altbeacon

I am trying to send two long values (latitude and longitude) in the beacon's data fields, as a list of long, but only the first long value gets through.
I tried to put both values, latitude and longitude, in the dataFields:
.setDataFields(listOf(latitude.toLong(), longitude.toLong()))
and the result is [53], which is just the latitude.
I tried to put the latitude in the dataFields and the longitude in the extraDataFields:
.setDataFields(listOf(latitude.toLong())) .setExtraDataFields(listOf(longitude.toLong()))
and the latitude is correctly set, while the extraDataFields remains empty.
Is there a constraint regarding the dataFields, such as being able to only hold one value, despite being a list of long?

Different beacon formats support different numbers of data fields and sizes.
iBeacon - 0 data fields
AltBeacon - 1 data field of one byte
Eddystone UID - 0 data fields
Eddystone TLM - 5 data fields of sizes 1, 1, 1, 4 and 4 bytes, respectively
You may also define custom formats with any number of data fields that fit into the packet.
If you use the setDataFields method to put more data bytes into the beacon than the format allows, the extra data will be ignored and not be included in the advertisement.
A common alternative approach for encoding latitude and longitude is to encode these in the major and minor identifier fields (ID2 and ID3) for iBeacon and AltBeacon.

Related

Filtering Alt beacon with manufacturer identifier and UUID begins with specific format

One of my use case requires to filter all the beacons which is generated by specific manufacturer and UUID starts with specific string.
The ALT beacon library (https://altbeacon.github.io/android-beacon-library/javadoc/reference/org/altbeacon/beacon/Region.html) provides Region class to filter the beacon based on the ID1, ID2, ID3.
I could not find any option to filter all the beacons at the library level which has specific manufacturer ID and the UUID begins with specific characters.
The API documentation with sample code to configure ALT Beacon library for filtering is appreciated and this helps to avoid additional filtering logic implementation at the application.
Filtering on a prefix of the UUID is unusual, but it is possible by defining a custom beacon layout and defining an additional identifier to be the UUID prefix. Because this new extra identifier will be treated as an independent identifier, it won't work like a string prefix -- its default representation will.be a hex string (without dashes).
If you want to filter on the first five bytes of the UUID for iBeacon, you'd set up a beacon parser like this:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-8,i:4-19,i:20-21,i:22-23,p:24-24")); // note the new 5 byte prefix identifier: i:4-8
Now each beacon will have four identifiers instead of three, the first of which will be the beginning 5 bytes of the UUID, the second the full UUID, the third the major and the fourth the minor.
You can set up a region to match the first five bytes of this UUID, 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 like this:
Region region = new Region("prefixRegion", "0x2F234454CF", null, null);
If you want the prefix to be a different length than 5, simply adjust the i:4-8 part of the layout above to end in a different offset than 8.

Create a JSON string with number of significant figures / decimal places based on key IOS OBJ C

I need to upload JSON data from an app (IOS) to the backend server.
The goal is to optimise the size of the upload packet which is JSON encoded as a NSString. The string is currently about 5MB but contains mostly doubles which have more precision than necessary.
The size of the packet can be reduced by around 40-50% by removing unnecessary decimal places in doubles. This has to be customisable based on the key.
What is the best way to create a JSON string with different numbers of significant figures or decimal places depending on the key.
You may need to do some experiments. Let's say you want to send data with two decimal digits, like 3.14 instead of pi. You know you have to turn all numbers into NSNumber. You would turn x into a number with two decimals by writing
double asDouble = 3.141592653;
NSNumber* asNumber = #(round (asDouble * 100.0) / 100.0);
However, you need to check that this always works; with some bad luck this could send 3.140000000000000000000001 to your server.
Obviously you can replace the 100.0 with 1000.0 etc. Do not replace the division with a multiplication by 0.01 because that will increase rounding errors and the chance that you get tons of decimal digits.
You might check what happens if you write
NSNumber* asNumber = #((float) asDouble);
If NSJSONSerialization is clever enough, it will send fewer decimals.

sqlite query for range search having text for ios app

I have a table with columns as LowerFrequency, HigherFrequency and ID. The frequencies entered have a suffix of khz or mhz. I want to search a specific frequency by checking the range it falls in i.e between the lower and higher frequencies and fetch the respective ID.
The query I implemented was as below but it returns a wrong output:
select tablename.ID where "100 khz" between tablename.LowerFrequency and tablename.HigherFrequency;
I know the reason is because of the khz that follows the integer. But I need some suggestions to handle this as I am not in a situation of changing the whole DB file because it is time consuming.
I will be integrating this DB with my iPhone app. So any solutions in Objective C would also be appreciated. I mean some kind of conversion.

proper data type for storing google maps lattitude and longitude values?

...I have a Grails domain class dealing with geo location data for interacting with google maps:
Float latitude
Float longitude
When the following values get saved to a db :
latitude : 2.5485291419153366, longitude : -76.03939712047577
I end up having : 2.54853;-76.0394 respectively.
What's the best way of preserving the initial values in this case?
Thanks in advannce
Another option would be to just store them as Strings. I know that seems odd, but you're probably just passing the values back to the maps API and not doing any real calculations yourself. If that is the case, Strings are easy. Just because something is a number, doesn't mean it has to be stored in a numeric data type.
You will probably want to use BigDecimal. Floating point numbers arn't garanteed to be 100% accurit while you can control the number of digits with BigDecimal. Grails doesn't offer constraints for this so you'll have to use methods as setScale to determine the number of digits to store. FOr more info see
http://download.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html
... in the end here's what I decided to go with:
BigDecimal latitude
BigDecimal longitude
static constraints = {
latitude( scale : 16 )
longitude( scale : 16 )
}

Telephone Number to Geolocation UK

Is there a service that provides latitude and longitude for UK phone numbers?
For example:
Query: 0141 574 xxx, Returns: (55.8659829, -4.2602205) [Glasgow City Centre]
Allow me to stress that I am not looking for a reverse-directory-enquires. I am more interested in 'local area' for things like weather by phone or "Where's my nearest Pizza Shop?"
If this service doesn't exist your suggestions on how to implement it or where to get data from would also be incredibly useful.
I am aware that Ofcom provides a list of area codes with a place name [1] suitable for geolocation, but I have my concerns about resolution. I see this as a particular problem in smaller towns and rural areas where an area code will cover a large geographical area.
Second Example:
Area Code: 01555, Ofcom: Lanark
However:
01555 860xxx is Crossford (4 miles W of Lanark)
01555 77xxxx is Carluke (5 miles NW)
01555 89xxxx is Lesmahagow (5 miles SW)
01555 840xxx is Carnwath (7 miles NE)
Therefore 01555 covers about ~80 sq miles. That's not particularly local.
[1] Ofcom Area Code Tool: http://www.ofcom.org.uk/consumer/2009/09/telephone-area-codes-tool/
You can get a resonable location for numbers allocated to BT.
The "L" digits map to a particular exchange within that area:
(02X) LLLL XXXX (2+8)
(011X) LLL XXXX (3+7)
(01X1) LLL XXXX (3+7)
(01XXX) LLXXXX (4+6)
(01XXX) LLXXX (4+5)
(01XXXX) LXXXX (5+5)
(01XXXX) LXXX (5+4)
For cable providers (especially those using fibre optic delivery), there is sometimes only one exchange per area code and therefore the numbers in each LL range cover the entire area code.
For numbers allocoted to other providers there's a similar problem. Additionally, those numbers may be allocated as VoIP and in use in another area or even in a completely different country. For non-BT numbers location data cannot be relied on.
For people who have moved and kept their number, location data will also be inaccurate.
That said, CodeLook does a reasonable job of showing the right data: http://www.telecom-tariffs.co.uk/codelook.htm
You may have a problem in that not all numerics after area codes are geographic. Some have been block allocated to Cable Providers. I know my own number has belonged to myself and also a person who lived about 5 miles northeast of my current location, the link... we belong to the same cable provider.
What sort of telephone numbers are they? If they are businesses, what do you think of the possibility of searching for the whole number using say, Googles API, and lifting the actual address from the page? - I know thats harder to do than that, just exploring some possibilities ..;-

Resources