Show the heading direction of a compass on a map - c#

I have a Windows Phone application with a map. On this map, there are several pushpins (different infos on the map) and a pushpin of the current position. I want to show the heading direction (the direction the user looks with his phone) on the current position pushpin (using the compass angle). I already have a custom control that rotates according to the compass value. What I don't know is how to incorporate it into the map, i.e. show it on the current position on the map.
Do you have any ideas?
Thank you very much.
PS: If you don't know what I mean, I intend to do something like it's available in the (Nokia) Here Maps .

I don't have a complete answer. What I know is you can add any control to a map using this technique:
myMap.Layers.Add(new MapLayer()
{
new MapOverlay()
{
GeoCoordinate = new GeoCoordinate(37.795032,-122.394927),
Content = new Ellipse
{
Fill = new SolidColorBrush(Colors.Red),
Width = 40,
Height = 40
}
}});
This comes from http://developer.nokia.com/Community/Wiki/What's_new_in_Windows_Phone_8
Now this will display a simple red dot, but I understand you can put just about any control in there. Use your control, bind the rotation to a value that will hold the rotation in your view model and I think you are quite done. Does this work for you?

Related

UWP MapControl: Center map around more than one point

I have a MapControl in my UWP C# app to which I have added some markers at certain coordinates. Now I want to zoom and adjust the map view so that all the markers can be seen on the same view, i.e. so that I don't have to zoom out or adjust the map center manually.
So, what I have is a list of points:
List<Geopoint> points;
now how do I get the correct map zoom and center?
The UWP Map control has a method to be sure certain points are in the visible area.
It's called TrySetViewBoundsAsync docs can be found here https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.maps.mapcontrol.trysetviewboundsasync
You use it like this
await ActivityMap.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(geopositions), null, MapAnimationKind.None);
So the class GeoboundingBox can be used with the TryCompute method to get the actual GeoboundingBox, docs https://learn.microsoft.com/en-us/uwp/api/windows.devices.geolocation.geoboundingbox.trycompute

Gmap.Net Marker at incorrect position but when the map is zoomed the marker goes to right place

I've a Windows Forms Application with a Gmap.Net controller, what I want to do is to add markers based on an outside sources that provides locations. The thing is that when I add a marker is initially drawn in an incorrect location, but after I zoom out it goes to the right place. So this is what I got so far:
My Map controller is declare to be located at Panama, Panama.
private void button2_Click(object sender, EventArgs e)
{
//Layer count is just a variable to add new OverLays with different names
var markersOverlay = new GMapOverlay("markers" + layerCount);
//Marker far away in Quebec, Canada just to check my point in discussion
var marker = new GMarkerGoogle(new PointLatLng(58.0032, -79.4957), GMarkerGoogleType.red_small);
markersOverlay.Markers.Add(marker);
gmap.Overlays.Add(markersOverlay);
layerCount++;
}
So when I press the button what I got is this (have in mind that the map location it's set to be in Panama and the marker in Canada):
And when I zoom out, the marker goes to the correct position in Canada.
Why my marker is been drawn in Panama initially?
P.D: I already check this question but it doesn't resolve my problem because I need to be adding more than 1 marker and myMap.UpdateMarkerLocalPosition(marker) is not a solution for me.
It's because you're adding the marker to the overlay that has not been added to the map's overlays. Try to switch the order of the statements as follows:
gmap.Overlays.Add(markersOverlay);
markersOverlay.Markers.Add(marker);
add a first marker at lat,lon = 0,0.
you can also make this marker invisible with setting its marker image as 1x1 pixel transparent png image.
first element of the marker do this kind of wrong placement.

WinRT Bing.Maps - how add a image with a lat/lon bounding box?

I am able to add an image to my map just fine via code.
However when I zoom in/out, the image stays the same. I would like it scale relative to the map.
In the WPF version of the Map, you could use an ImageBrush for a MapPolygon and it would be constrained to the bounding box.
I tried the solution from this SO question, but it seems to have no effect on the Image.
imageLayer.Children.Clear();
MapLayer.SetPosition(_vm.RadarImage, new Location(_vm.Overlay.LatN, _vm.Overlay.LonW));
imageLayer.Children.Add(_vm.RadarImage);
shapeLayer.Shapes.Clear();
var rect = new MapPolygon();
rect.Locations.Add(new Location(_vm.Overlay.LatN, _vm.Overlay.LonW));
rect.Locations.Add(new Location(_vm.Overlay.LatS, _vm.Overlay.LonW));
rect.Locations.Add(new Location(_vm.Overlay.LatS, _vm.Overlay.LonE));
rect.Locations.Add(new Location(_vm.Overlay.LatN, _vm.Overlay.LonE));
rect.FillColor = Colors.Green;
shapeLayer.Shapes.Add(rect);
mappy.SetView(new LocationRect(new Location(_vm.Overlay.LatN + 0.0001, _vm.Overlay.LonW + 0.0001), new Location(_vm.Overlay.LatS - 0.0001, _vm.Overlay.LonE - 0.0001)));
This is the correct scaling.
When you zoom once via the Navigation, you can see the image is now larger than the Polygon
There isn't a simple solution for this. I have put together a sample app that shows one approach to do this. You can find it here: http://code.msdn.microsoft.com/Binding-and-Image-to-a-01a56e48 What I did was add a Canvas to the map, and then use the map to calculate the pixel coordinates of the bounding box for the image. I then used these pixel coordinates to scale and position the image on the canvas overtop the map. I've done something similar to create custom polygons that support image brushes in the past but haven't uploaded that code sample yet.

Control.PointToScreen on Windows Phone

Is there a way to get a control's absolute screen co-ordinates on Windows Phone? also, will help if that method will work with UserControl components. WPF seems to have Control.PointToScreen, which isb't in the WP APIs
The idea is I'm trying to use a Callout control to point to a UserControl on the screen as a help bubble, and the anchor point doesn't take in absolute coordinates either - so it's a huge connected problem which I'll build up as an answer to this post.
Use UIElement.TransformToVisual()
something like this should do the trick:
var control = this; // assign the control you want to get the position of.
var transform = control.TransformToVisual(Application.Current.RootVisual);
var controlPosition = transform.Transform(new Point(0, 0));
probably you could try Control.MousePosition instead
is this want you want (though it's for WP7): How do you find the screen position of a control in silverlight on WP7?

Shape from Pushpins, actions on them

I am very curious, I have for example a app to localize our property, our first, second house, favorite park and we can add pushpins to corners of this property in a way to form a shape(triangle, square, polygon etc), not a line or point.
How to create this shape, there is a method to calculate the surface area? Change a background for example to color yellow between these pushpins ?
When we created a shape we can chose from the listbox or map to delete this shape or go to there using GPS, i wrote something like that in Simulate my current position
I think its a interesting app but i need your help ;)
Try getting the geocoordinates of each pushpin and using maths? I guess you could assume the flatness of the Earth over a small area (like a house) but over larger you'll need to account for curvature.
As for colouring the shapes in, I don't think there's a way to do this using the Map control.

Categories

Resources