Xamarin Forms Maps Bits

I ran across a couple of small issues tonight with my work with the Xamarin Forms Map, and it had to do with the precision of the values that I was using for the Center property that I setup in my previous post.

Normally in the Android emulator with Visual Studio, it has a preset starting location. For my app, I wanted something a little closer to home. To get the values for the MapSpan object, I was just outputting the values for the fields from the Center property that I had setup to figure out where I wanted to start from.

When I used those values as my initial start point for the map, I was putting in the full precision that the Visual Studio debugger was showing, approximately 15 digits after the decimal place. When I started forcing these values in, the map wouldn’t update its position.

I then started to play around with the location services in the emulator and the map would update in response to those values. Looking at the values displayed by the emulator, they only used 4 digits. I made the change and everything started working again. Assuming I am in the view model and am using the attached property to bind to set the center point of the map, this didn’t work for me:


// underlying Map.MoveToRegion call doesn't do anything
Center = new MapSpan
(
	new Position(48.0111563131213188, -122.0096835170062306),
	0.0096835170062306,
	0.0111563131213188
);

Instead, try using it like this:


// underlying Map.MoveToRegion call now works
Center = new MapSpan
(
	new Position(48.0111, -122.0096),
	0.0096,
	0.0111
);

I have yet to go looking at why this is the case but it seems likely that the map control can only handle that level of accuracy. If you are finding that you can’t seem to control what the map is displaying, check out the precision of the values in the MapSpan object. And if anyone reading this knows for sure what is happening here, feel free to chime in.

I will be attending a Xamarin dev workshop at Microsoft Vancouver, perhaps there will be someone there that can answer this definitely.

Hope that helps.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s