0

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?

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

1 Answers1

4

Have you tried setting the custom location within the simulator?

https://bencoding.files.wordpress.com/2011/12/step2.png

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:

  1. Set the location in iPhone Simulator
  2. http://bencoding.com/2011/12/28/setting-you-location-in-the-ios-5-0-simulator/
Community
  • 1
  • 1
matthewrdev
  • 11,930
  • 5
  • 52
  • 64
  • AH! i never thought of looking at the Emulator application .. for any settings. I kept thinking these were all defined in the Xam studio! That helps :) now .. to my next question... – Pure.Krome Oct 22 '13 at 00:40