Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add the "you are here" marker to Bing Maps Control

How do you add the "you are here" marker to the Bing Maps control? On the phone this is represented as a circle within a square and then there is an outer circle representing the location accuracy.
It looks like you could do it with a pushpin and a polgon but I'm hoping there is an easier/better way

like image 824
David Hayes Avatar asked Aug 01 '11 15:08

David Hayes


People also ask

How do I add a marker to Bing Maps?

Adding markers and navigation line Markers can be added to the layers of Bing Maps by setting the corresponding location's coordinates of latitude and longitude using markerSettings .

How do I edit Bing Maps?

Sign in to the Bing Maps Dev Center. Click Update or view account details to view your account details, and then click Edit. Make your changes to the account information, and then click Save.

Does Bing Maps have a compass?

By default, the map shows a toolbar with controls that the user can use to navigate the map. These controls are compass, zoom and tilt.

How many destinations can you add to Bing Maps?

Bing Maps allows you to add multiple destinations/stops to the route up to 25 stops. Plan a route and choose from options like walking, biking, public transport mode, or driving directions. You can also choose to print the routes you plan. Save the routes and destinations.


2 Answers

You can use the GeoCoordinateWatcher class, which gives your current location, and then add a simple pushpin. I don't think the pushpin is a bad choice and/or a hard one to use.


GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();

GeoCoordinate loc = watcher.Position.Location;

if (loc.IsUnknown == true)
{
    // Cannot retrieve the GPS position
    return;
}

MyBingMap.SetView(loc, 17);

MapLayer pushPinLayer = new MapLayer();

MyBingMap.Children.Add(pushPinLayer);

Pushpin p = new Pushpin();

p.Content = "YOU ARE HERE";
p.Location = loc;

pushPinLayer.AddChild(p, loc, PositionOrigin.BottomLeft);    
like image 143
Tuco Avatar answered Sep 30 '22 13:09

Tuco


You asked two questions and Tuco has given you a good answer to the first one: how to add the pushpin. Here's the answer to your second question: how to style it.

To get the pushpin to look like a yellow dot in a black diamond with a white nimbus, you need to define this style and apply it to the pushpin. I could also tell you how to style white numbers centred on a black circle with a white nimbus, but then I'd have to kill you.

xmlns:m="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"

<Style x:Key="CurrentLocationPushpinStyle" TargetType="m:Pushpin">
  <Setter Property="BorderBrush" Value="#FFF4F4F5" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate>
        <Grid>
          <Rectangle Fill="Black" Height="25" Stroke="White" StrokeThickness="2" Width="25" RenderTransformOrigin="0.5,0.5">
            <Rectangle.RenderTransform>
              <CompositeTransform Rotation="45" TranslateX="-10" TranslateY="11"/>
            </Rectangle.RenderTransform>
          </Rectangle>
          <Ellipse Fill="Yellow" Height="11" Stroke="Yellow" Width="11">
            <Ellipse.RenderTransform>
              <CompositeTransform TranslateX="-10" TranslateY="11"/>
            </Ellipse.RenderTransform>
          </Ellipse>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

A yellow dot is soooo last year. Mango uses a blue dot.

like image 38
Peter Wone Avatar answered Sep 30 '22 13:09

Peter Wone