I'm using BingMapsImagery (I have a key), and I can get the map to load fine following the samples in the "Samples Browser".
However, I’m having trouble programmatically setting the map center and zoom levels. For instance, I know that the Geographic center of the United States is latitude=39.833 and longitude=-98.583. When the map is first displayed, I want that location to be the center of the map and I want to set a zoom level showing the entire United States.
I also want to add navigational controls allowing the user to quickly navigate to a specific location (again displayed at the center of the map) with some appropriate level of zoom. For example, if the user selects “Houston, Texas”, then Houston, Texas would be displayed at the center of the map and the zoom level would be appropriate to see Houston and the surrounding area. I have the geographical coordinates for all locations that I want to display in this manner, and I’ll also know generally how much zoom I need for each location.
My question is how do I configure the XamGeographicMap control to have a specific geographic location (latitude, longitude) as the center with the pre-defined level of zoom? Other controls I’ve seen implement this fairly intuitively by simply setting the center latitude/longitude and a ZoomLevel property, but I don’t see anything like that with the XamGeographicMap control.
Thanks, Steve
Hi Steve,
You should use the XamGeographicMap’s GetZoomFromGeographic method. Here is a sample in the Samples Browser that might be helpful to you:
http://samples.infragistics.local/sllob/geographic-map/sl/#/mapping-geo-regions
Here is the code snippet:
this.GeoMap.WindowRect = this.GeoMap.GetZoomFromGeographic(geoRect);
geoRect is the geographic rectangle that you want to zoom.
Hope this helps!
Thanks,
Diyan Dimitrov
Thanks for the response and I've seen that method, however I don't see how it actually works in relation to geographic coordinates (latitude and longitude). For example, I've attached a simple sample project. If you click the "Reset 2" button, it will position the map exactly as I want it when the app first starts using this code snippet (I was only able to determine the Rect parameters by capturing them in debug mode):
Rect geoRect = new Rect(-120.261862, 17.621203, 48.572741, 37.576602);
Rect windowRect = DataMap.GetZoomFromGeographic(geoRect);
DataMap.WindowRect = windowRect;
However, the true geographic center of the US is 39.8333° N, 98.5833° W. How do the true geographic coordinates convert to the parameters used in the code snippet? Also, do you have any suggestions about determining the height and width parameters of the Rect when all I really know is something like "zoom level of 20"?
Thanks.