Windows Phone - check if MapCore.SetView doesn't zoom too much

I am using method SetView to zoom for two points in map but when they are too close I am too zoomed. So I hope I can check something like this:

myMap.SetView(bounds);
if (myMap.ZoomLevel > Constants.DefaultZoomLevel)
    myMap.ZoomLevel = Constants.DefaultZoomLevel;

But method SetView isn't immediately set ZoomLevel property. What can I do to fix it? How can I set some zoom level border? Thanks

Edit:

I found that in 8.0 sdk there is ZoomLevelChanged event? This could be useful for me. So is there possible how to get it worked in 7.1?

Answers


I tried several solutions and these are my results (I needed working for WP7.1, with just targeting for WP8 there could be easier solution):

  • Use of TargetZoomLevel

Like this:

myMap.ZoomLevel = Math.Min(myMap.TargetZoomLevel, maxZoomLevel);

Doesn't solve my problem because SetView set ZoomLevel after this code execute. Map was just blinking between ZoomLevel from SetView and maxZoomLevel (I have timer for checking positions so that is why it was blinking and isn't good for me).

  • Use of MapZoom event

Like this:

private void map1_MapZoom(object sender, Microsoft.Phone.Controls.Maps.MapZoomEventArgs e)
{
    if (((Map)sender).ZoomLevel > maxZoomLevel)
    {
        e.Handled = true;
    }
}

Problem: MapZoom event handler is not fired when SetView it's used.

  • Check distance and set ZoomLevel if distance is little:

    public static double GetDistanceBetweenPoints(LatLon firstPoint, LatLon secondPoint)
    {
        var sCoord = new GeoCoordinate(firstPoint.Lat, firstPoint.Lon);
        var eCoord = new GeoCoordinate(secondPoint.Lat, secondPoint.Lon);
        return sCoord.GetDistanceTo(eCoord);
    }
    

usage:

var distance = LocationHelper.GetDistanceBetweenPoints(carPosition, userPosition);
if (distance < MinMetersDistance)
    myMap.ZoomLevel = maxZoomLevel;

Problem: Again blinking. Sometimes I set ZoomLevel by this code. Other time it was set by SetView.

  • My real solution:

I just check distance between two points like in previous dot. But this time if the distance was little I just create new points from the old ones and set them in new positions (latitude and longitude) which was in min distance (one on the left side I moved more to left and second on the right side I moved more to right). Then I used SetView on new points.


Need Your Help

3D struct in .Net?

.net height width structure depth

I always prefer to use existing (.Net source originated) structures and enums, over self creating them. I want to have a structure to define a 3d size. For 2D, SizeF does the job. What about width,

High load on Cassandra nodes

cassandra datastax-enterprise opscenter

For some reason I experience high load on my Cassandra nodes. Here are some information to get the picture.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.