I have successfully acquired location in my BlackBerry through the criteria;
BlackBerryCriteria myCriteria = new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE)
The location was acquired in the following scenario:
No mobile coverage on the BlackBerry handset
Active internet connection
No GPS fix
My question is what is this location that is acquired - GPS or Cell Tower Triangulation?
I believe since the location is acquired indoors without any GPS fix, it should be a Cell Tower location. I do not have mobile coverage yet the location is acquired. How is the cell tower information obtained then? If I was using a roaming GPRS connection, would the location obtained be any different (based on the IP settings)? For reference, below is the complete code of obtaining the location:
try
{
BlackBerryCriteria myCriteria = new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE);
try
{
BlackBerryLocationProvider myProvider = (BlackBerryLocationProvider)
LocationProvider.getInstance(myCriteria);
try
{
BlackBerryLocation myLocation = (BlackBerryLocation)myProvider.getLocation(30000);
double _longitude = myLocation.getQualifiedCoordinates().getLongitude();
double _latitude = myLocation.getQualifiedCoordinates().getLatitude();
setLocation(new Coordinates(_latitude, _longitude, 0.0f));
}
catch (InterruptedException e)
{
showException(e);
}
catch (LocationException e)
{
showException(e);
}
}
catch (LocationException e)
{
showException(e);
}
}
If I'm reading your description correctly:
No mobile coverage on the BlackBerry handset
Active internet connection
No GPS fix
you must have a Wi-Fi connection then (active internet, but no mobile coverage).
So, the device is then using Wi-Fi geolocation (aka WLAN geolocation), which was added a bit late in the development of BlackBerry Java (although, it's still been available for a while ... OS 6.0+).
http://devblog.blackberry.com/2011/09/wifi-geolocation-launch/
Obviously, the test is to turn off your Wi-Fi, and see if you still get location fixes.
Related
My application collects location data when the user presses on a certain button, but if the user turns gps option off then turns it back the location no more works even if the gps is enabled.How to handle such a thing in flutter??
As per example in this link https://pub.dartlang.org/packages/location you should put add below code in button's click event.
var location = new Location();
// Platform messages may fail, so we use a try/catch PlatformException.
try {
currentLocation = await location.getLocation;
} on PlatformException {
currentLocation = null;
}
I've looking here on Forums, on the monotouch samples GIT hub, and never found a really functional sample to use CoreBluetooth in order to achieve the following:
1.Check if is there a device that match a criteria(by name or some identifier of the device) paired and connected
2.If paired but not connected, try connect to it
3.If connection fails, then show a list of the bluetooth devices that matches the criterias on topic 1 so the user can select and connect to it
Note: The device I'm trying to connect uses SPP but is Apple MFi certified. It is a credit card reader over bluetooth and some of then even implement ExternalAccessory protocols
The CoreBluetooth samples page is empty http://developer.xamarin.com/samples/ios/CoreBluetooth/
I've trying this pretty simple sample that never get the events called after the scan:
public static class BTHelper
{
private static CBCentralManager manager;
private static CBUUID UUID;
static BTHelper()
{
manager =
manager.DiscoveredPeripheral += OnDiscovery;
manager.ConnectedPeripheral += OnConnected;
manager.DisconnectedPeripheral += OnDisconnected;
UUID = CBUUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
}
public static void CheckBluetooth()
{
manager.ScanForPeripherals(new[] { UUID });
}
static void OnDisconnected(object sender, CBPeripheralErrorEventArgs e)
{
Console.WriteLine("Disconnected - " + e.Peripheral.Name);
}
static void OnConnected(object sender, CBPeripheralEventArgs e)
{
Console.WriteLine("Connected - " + e.Peripheral.Name);
}
static void OnDiscovery(object sender, CBDiscoveredPeripheralEventArgs e)
{
Console.WriteLine("Found - " + e.Peripheral.Name);
}
}
Can anyone help? I've being really tired of googling and looking of many questions on SO with no real answer.
#XamarinTeam, you guys should provide a sample on how to use it... We are lost without reference...
Thank, really appreciate any help...
Gutemberg
It seems like you are looking at wrong documents.Core Bluetooth only allows you to communicate with Bluetooth Low Energy (BLE) devices using the GATT profile. you can not scan SPP device with corebluetooth.
For your MFI device, you need to check External Accessory framework , It allows communication with 'legacy' Bluetooth devices using profiles such as the Serial Port Protocol (SPP).
To answer your question:
: 1.Check if is there a device that match a criteria(by name or some identifier of the device) paired and connected
You can use showBluetoothAccessoryPicker function of EAAccessoryManager to get list of Available devices, read more here
2.If paired but not connected, try connect to it
There is not any documented way to check for this. You can not initiate connect from app without showBluetoothAccessoryPicker . You can monitor for
EAAccessoryDidConnect notification. if this method is not called, and showbluetoothaccessorypicker 's complition get called, your device is not connected.
3.If connection fails, then show a list of the bluetooth devices that matches the criterias on topic 1 so the user can select and connect to it
1)
After completion of showbluetoothaccessorypicker You can check in ConnectedAccessories . If its not avaiable, call showbluetoothaccessorypicker to display list of accessories.
Sample code for using External Accessory framework in your code
EAAccessoryManager manager= EAAccessoryManager.SharedAccessoryManager;
var allaccessorries= manager.ConnectedAccessories;
foreach(var accessory in allaccessorries)
{
yourlable.Text = "find accessory";
Console.WriteLine(accessory.ToString());
Console.WriteLine(accessory.Name);
var protocol = "com.Yourprotocol.name";
if(accessory.ProtocolStrings.Where(s => s == protocol).Any())
{
yourlable.Text = "Accessory found";
//start session
var session = new EASession(accessory, protocol);
var outputStream = session.OutputStream;
outputStream.Delegate = new MyOutputStreamDelegate(yourlable);
outputStream.Schedule(NSRunLoop.Current, "kCFRunLoopDefaultMode");
outputStream.Open();
}
}
and
public class MyOutputStreamDelegate : NSStreamDelegate
{
UILabel label;
bool hasWritten = false;
public MyOutputStreamDelegate(UILabel label)
{
this.label = label;
}
public override void HandleEvent(NSStream theStream, NSStreamEvent streamEvent)
{
//write code to handle stream.
}
}
There is not any perticular demo for using Exeternal Accessory framework,
but You can check this sample code for understanding how it works.:
Whole Project
AccessoryBrowser class
Hy guys, i need to find altitude, bearing and gps accuracy in my iPhone app. i've done this on my android app. in android, i did it like this :
public void onLocationChanged(Location location) {
if (isBetterLocation(location, lastValidLocation)
&& isEnable) {
lastValidLocation = location;
longitude = location.getLongitude();
latitude = location.getLatitude();
altitude = location.getAltitude();
speed = location.getSpeed();
accuracy = location.getAccuracy();
bearing = location.getBearing();
locationProvider = location.getProvider();
onPositionChanged(
LocationService.this,
new GeoPoint(location.getLongitude(), location
.getLatitude()));
}
}
how can i do the same thing in iOS ?
i've tried to get it from CLLocation, but it return null/0,0000/-1.0000 ..
btw, i get this result when i test it on iOS Simulator.
Thanks.
Regards.
The simulator is not a good place to test Core Location stuff. It only simulates a specific location but if you want to test speed, bearing etc. you're better of trying on a real device.
You need to use the class CLLocationManager (Apple doc) and fetch the data using the delegate protocol available. For example, if you want the heading you implement the method locationManager:didUpdateHeading: and call the method startUpdatingHeading on the location manager.
var initialLocation;
var siberia = new google.maps.LatLng(60, 105);
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag = new Boolean(); // Try W3C Geolocation (Preferred)
if (navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); // THERES OUR LAT/LONG VALUES
ajaxPost(initialLocation);
},
function() {
handleNoGeolocation(browserSupportFlag);
}); // Try Google Gears Geolocation
} else if (google.gears) {
browserSupportFlag = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.latitude, position.longitude); // THERES OUR LAT/LONG VALUES
ajaxPost(initialLocation);
},
function() {
handleNoGeoLocation(browserSupportFlag);
}); // Browser doesn't support Geolocation
} else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
initialLocation = new google.maps.LatLng(geoip_latitude(), geoip_longitude()); // THERES OUR LAT/LONG VALUES
ajaxPost(initialLocation);
navigator.notification.alert('Geolocation service failed', // message
'Geolocation Error!', // title
'OK' // buttonName
);
} else {
initialLocation = new google.maps.LatLng(geoip_latitude(), geoip_longitude()); // THERES OUR LAT/LONG VALUES
ajaxPost(initialLocation);
navigator.notification.alert("Your browser doesn't support geolocation. We've placed you in Siberia.", // message
'Browser Error!', // title
'OK' // buttonName
);
} // THERES OUR LAT/LONG VALUES
}
This is code we use in our Sencha Touch application to get the users current position. Now, I tested this code using a 3G connection on my Droid HTC Eris, and it gave me a location 6 miles away from myself, which is fine, I can live with that, I could probably even live with a little bit more.
However, testing on an iPod Touch using Wifi, connecting to our in home router, it put us 147 miles from our current location. Now, this might make sense if our router here had some weird IP address or something like that (w/e this code actually uses to find location if it doesn't fall back to IP), but I testing geolocation straight from google from a laptop also hooked up to our wifi here and it puts us less than 1 mile from overhead.
What kind of situation could make this happen? Is this something we are just going to have to live with until geolocation further advances? If so, that's fine, I just want to know if there's something we could do to improve this. 147 miles away is a little crazy, considering every other source we've tried puts us within 10 max.
The only thing I can think of is that google has some correction listings in it's own databases. What is probably happening is your ip is registered to a holdco which is 147 miles away from you. For example if whois my IP it is registered to a holding company which is about 50 miles away from me. Non-corrected databases (such as the ones you typically buy online) show me in that town. Google, whoever does not.
I want to know if the device has GPS or not, how could I do that for the devices below v 5.0 ?
Have a look at docs for Location Provider. Try this code on a few devices in different situations and I think it should work:
try {
LocationProvider lp = LocationProvider.getInstance(null);
if (lp == null) {
//Device doesn't currently have GPS enabled
} else {
//Device has GPS enabled
}
} catch (LocationException le) {
//Device's GPS is currently permanently disabled
}
You have to check if Java ME's JSR 179 is available.