How can I get a fake 'current location' when creating an IOS Map with Xamarin Studio and the iPhone Emulator? - iphone

Problem:
When using the Xamarin iPhone emulator, the current location is not getting set on the map.
Details:
I'm trying to plot my current location on a Map, in a sample iPhone app I'm learning with Xamarin Studio and the iPhone emulator.
I have the map displayed but there's no current location getting set.
I did get asked to use my Current Location (which I'm sure I said yes/ok to) .. but it keeps centering it in San Fran, near union square :(
When ever I run my emulato, I see this text pop up:
2013-10-22 09:27:45.018 MyApp [6018:1503] MonoTouch: Socket error while connecting to MonoDevelop on 127.0.0.1:10000: Connection refused
So i'm not sure if that has something to do with it?
Ok, so lets look at some code I've got.
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
map.MapType = MKMapType.Standard;
map.ShowsUserLocation = true;
map.ZoomEnabled = true;
map.ScrollEnabled = true;
map.DidUpdateUserLocation += (sender, e) => {
if (map.UserLocation != null)
{
CentreMapAtLocation(map.UserLocation.Coordinate.Latitude,
map.UserLocation.Coordinate.Longitude);
}
// User denied permission, or device doesn't have GPS/location ability.
if (!map.UserLocationVisible)
{
// TODO: Send the map somewhere or hide the map and show another message.
//CLLocationCoordinate2D coords = new CLLocationCoordinate2D(37.33233141,-122.0312186); // cupertino
//MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude));
//mapView.Region = new MKCoordinateRegion(coords, span);
}
};
private void CentreMapAtLocation(double latitude, double longitude)
{
CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D (latitude, longitude);
MKCoordinateRegion mapRegion = MKCoordinateRegion.FromDistance (mapCenter, 10000, 10000);
map.CenterCoordinate = mapCenter;
map.Region = mapRegion;
}
So it's nothing too crazy, IMO.
Anyone have any suggestions?

Have you tried setting the custom location within the simulator?
I tend to use a combination of the Custom Location setting and this tool when I need to verify locations within the iOs simulator. You won't need to make any changes to your code for this to work; it just pipes the set location into the location manager within iOs.
To my knowledge, the simulator does not support GPS or WiFi based location therefore it can't use your current location like a physical device. Perhaps someone else can clarify this.
For further information, see:
Set the location in iPhone Simulator
http://bencoding.com/2011/12/28/setting-you-location-in-the-ios-5-0-simulator/

Related

Flutter : Check GPS Location Mode

I have project related using maps and tracking location user , for this i used Geolocator Package. I need to check current location of user , in my flow project first i check last position of user , if last position null then i check current position of user.
Code
Position _currentPosition;
Position get currentPosition => _currentPosition;
Future<void> getCurrentPosition() async {
try {
Position lastPosition = await Geolocator().getLastKnownPosition();
if (lastPosition != null) {
print("Success Get Last Position...");
_currentPosition = lastPosition;
} else {
final currentPosition = await Geolocator().getCurrentPosition();
if (currentPosition != null) {
print("Success Get Your Current Position...");
_currentPosition = currentPosition;
} else {
throw "Can't Get Your Position";
}
}
} catch (e) {
throw e;
}
notifyListeners();
}
Then i calling getCurrentPosition Function on my button OnPressed to get location user like this :
Button GetLocation
void goToMaps() async {
final mapsProvider = context.read<MapsProvider>();
try {
print('Get Location User');
await mapsProvider.getCurrentPosition();
print('Success Get location User');
} catch (e) {
globalF.showToast(message: e.toString(), isError: true, isLongDuration: true);
}
}
First Problem is , When GPS Location Mode is Device Only I can't get LastPosition or Current Position it never print Success Get Location User and still print Get Location User.
Second Problem is , When Gps Location Mode is Battery Saving user location i got is very inaccurate, compared i used mode High Accuracy.
My question is , How can i check if gps location mode != High Accuracy , then i can show warning user to set the gps to High Accuracy.
Similiar Like this question
Thank's.
For the second problem, it happens because in High Accuracy mode android uses both GPS and network location, but in Battery Saving mode GPS module is turned off. If it was native Android, you could check provider of the location if you get location from LocationManager. But provider is not available in Flutter in Position class. You can instead use accuracy. If it is greater than a threshold and not suitable for your application, you can suggest the user to turn on High Accuracy mode.
Another options would be to use other package than Geolocator (however I'm not aware of any package that provides necessary interface) or to modify source code of Geolocatior so that it provides information about which mode is currently active.

How to show current location indication

I'm using the Flutter SDK Version 4.3.1.0.
I get my location updates from the geolocator plugin and want to show the location on the HERE map. It correctly centers the map to the current location but there is no location indicator.
I currently use the following code. What else do I need?
void _showPosition(final GeoCoordinates coordinates) {
_mapView.mapScene.loadSceneForMapScheme(MapScheme.greyDay, (MapError error) {
if (error != null) {
print("Map scene not loaded. MapError: " + error.toString());
return;
}
_mapView.camera.lookAtPointWithDistance(coordinates, 1000);
});
}
I'm using the Flutter Channel beta, v1.17.0-3.4.pre
The HERE SDK for Flutter does not contain a pre-configured location indicator. You can easily create one by adding a circle item onto the map:
For this I would recommend using a MapPolygon that contains a GeoCircle shape. You can then also update the radius of the GeoCircle on the fly to indicate the current horizontal accuracy of the geolocator plugin.

Google maps V2 android get current location

Im trying to place a marker on the position i am, this way:
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_container)).getMap();
googleMap.setMyLocationEnabled(true);
My question is, how to get coordinates from myLocation, i tried, googleMap.getMyLocation().getLatitude() and googleMap.getMyLocation().getAltitude() right after googleMap.setMyLocationEnabled(true), but app crashes, another thing i did was Location loc=lm.getLastKnownLocation(provider) but are not the same coordinates and the marker is placed in the wrong place.
How can you people help me?
SupportMapFragment mf =(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mMap = mf.getMap();
mMap.setMyLocationEnabled(true);
mMap.setMapType(mMap.MAP_TYPE_NORMAL);
Just add these two lines of code to get current location on Maps
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
and when you long press on any location on map add this code to get its location
googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng arg0) {
double alt = arg0.latitude;
double alo = arg0.longitude;
MarkerOptions marker1 = new MarkerOptions().position(new LatLng(alt, alo)).title("Lat ="+alt+" Lang="+alo);
googleMap.addMarker(marker1);
}
});

How can we know that map Coordinates are in current region or not in current region?

I am working on map view app.I want know that how we can identify that coordinates are in my current region(Map region that bound with screen) or outside of it.
Thanks In Advance.
You have different options. You can see this sample code from apple: Regions. That, has I understand, check the device position by the antenna's position.
Or tracking device position, and check if is inside a region defined by You. Check this question
If you find a better solution, please let me know.
EDIT:
To check if a coordinate is visible in the map try using this:
// Your coordinates - Lisbon for example
float lisbonLatitudeValue = 38.7069320;
float lisbonLongitudeValue = -9.1356321;
CLLocationCoordinate2D lisbonCoordinates = CLLocationCoordinate2DMake(lisbonLatitudeValue, lisbonLongitudeValue);
if (MKMapRectContainsPoint(mapView.visibleMapRect, MKMapPointForCoordinate(lisbonCoordinates)))
{
// do something
NSLog(#" - Lisbon is visible");
}
else {
// do something
NSLog(#" - Lisbon is not visible");
}
Hope it helps

Is it possible for a web app to gather an iPhone's accelerometer data? If so, how?

Is it possible for a web app to gather an iPhone's accelerometer data? If so, how? I would think they might have in the Safari Web browser an API with such functionality.
If it is possible could someone send me a link to pages with specific coding information.
Found this snippet from here with a bit of Googling.
window.ondevicemotion = function(event) {
ax = event.accelerationIncludingGravity.x
ay = event.accelerationIncludingGravity.y
az = event.accelerationIncludingGravity.z
rotation = event.rotationRate;
if (rotation != null) {
arAlpha = Math.round(rotation.alpha);
arBeta = Math.round(rotation.beta);
arGamma = Math.round(rotation.gamma);
}
}