Continuously Display Lat Lon Coordinates in a Bing Maps Silverlight App

by James Richards April 12, 2010

Overview

This article presents code and a brief tutorial showing how to continuously display the real world latitude / longitude coordinates of the mouse location in a Bing Maps Silverlight Application.

You can view a live sample or download the source code.

Tutorial

Create a new Bing Maps Silverlight application called LatLonApp using the steps shown in my previous Getting Started with the Bing Maps Silverlight control post.

Open the solution in Blend 3, and open the MainPage.xaml user control.

Select the Map control in the Objects and Timeline Window

image

In the upper right hand corner, enter the name “MyMap” for the Name property in the Properties window and hit return.

image

Select the TextBlock tool in the toolbar, and click and drag on the artboard to add new text block to the project.

image

Position the text block in the lower right, just above the scale bar. Change the name the text block to “Coords”.

In the Properties window, set the Text property to “Lat, Lon” and the justification to Right.

image

image

Ensure that the Horizontal Alignment is set to Right, the Vertical Alignment is set to Bottom, the Left and Top Margins are set to 0 and the Right and Bottom margins are set to 5 and 57 respectively.

image

Notice how the text on the scale bar has a 1 pixel white drop shadow. Next, we’ll duplicate that effect for the Coords text block.

Click on the Assets tab in the upper left, and then select the Effects category. This will display any effects you have registered with Blend on the right hand side of the split window.

image

Drag the DropShadowEffect onto the Coords text block.

image

This will add the effect to the text block, select the effect in the Objects and Timeline window, and display the effect’s properties in the Properties window on the right.

Change the Blur Radius to 1, the Color to White, and the Shadow Depth to 1.

image

Now the text block is styled in the same way as the scale bar text.

image

Select the Map in the Objects and Timeline window or on the artboard and click the Events icon in the upper right hand corner of the Properties window.

image

Find the MouseMove event, enter MyMap_MouseMove and hit enter.

image

This will create a new event handler and open up the code behind file MainPage.xaml.cs.

image

At this point you can either code up the event in Blend, or switch back to Visual Studio. I prefer to switch back to Visual Studio for the Intellisense. Note that you could also have switch back earlier and created the event in Visual Studio as well.

Make sure that all of the files are saved before switching back by choosing Save All from the File menu or pressing Ctrl+Shift+S.

When you switch back to Visual Studio it will notice that the files have been modified and present a dialog asking if you want to reload the file(s). Click Yes to All.

image

Open the MainPage.xaml.cs and add a using statement for the Microsoft.Maps.MapControl namespace.

Add the following code to the MyMap_MouseMove event.

private void MyMap_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
    Point viewportPoint = e.GetPosition(MyMap);
    Location location;
    if (MyMap.TryViewportPointToLocation(viewportPoint, out location))
    {
        Coords.Text = String.Format("Lat: {0:f4}, Lon: {1:f4}",
            location.Latitude, location.Longitude);
    }
}

This code gets the current mouse position in Viewport coordinates and transforms the Point to a latitude longitude Location. If the transformation is successful, the latitude and longitude are rounded to 4 decimal places and the Coords text block is update to display the coordinate.

Press F5 to compile and run the project. As you move the mouse around the map, the coordinates are displayed above the scale bar.

image

Wrapup

In this article you learned how to continuously display the real world latitude / longitude coordinates of the mouse location in a Bing Maps Silverlight Application.

You can view a live sample of the application or download the source code.

Additional Resources

Tags: , , ,

Bing Maps | Silverlight

Getting Started with the Bing Maps Silverlight Control, Visual Studio 2008 and Blend 3

by James Richards April 08, 2010

Overview

This walkthrough shows how to create a new Bing Maps Silverlight Control project with either Visual Studio 2008 SP1 or Blend 3. While some of this material has been covered on other sites and blogs, I’m writing about it here for two reasons:

  1. Some of the other posts are now outdated, using older, beta or CTP versions of the APIs and development tools.
  2. In future posts about developing with the Bing Maps Silverlight Control, I want to be able to refer to this “Getting Started” guide so I don’t have to keep repeating the basics.

Download and Install the Development Tools

If you haven’t already done so, download and install the following applications, SDKs and Toolkits:

Required

VS2008

Microsoft Visual Studio 2008 SP1 (Includes .NET Framework 3.5 SP1)

Silverlight Microsoft Silverlight 3 Tools for Visual Studio 2008 SP1

Blend

Expression Blend 3 or Expression Studio 3
Bing Bing Maps Silverlight Control SDK v 1.0.1

Optional

SilverlightToolkit Microsoft Silverlight 3 Toolkit November 2009

 

 

More...

Tags: , , ,

Bing Maps | Silverlight

My Favorite Tweets from the ESRI BPC / Devsummit - Day 5

by James Richards March 25, 2010

Presenting the final day of my favorite tweets from the ESRI Business Partners Conference / Developer Summit. Many thanks to all the Tweeps who kept the rest of us informed. I hope my small role of documenting my favorites has helped a few others.

  • http://twitpic.com/1atozp - Empty halls at #devsummit. Guess the party last night was a success. #earlybirdsession - via @martenhogeweg
  • #MVC, test-driven development & #IOC shown with #Cairngorm 3 #devsummit #flex #as3 - via @dafkobyte
  • Extending the tiledmapservicelayer in silverlight with @rex_hansen using openstreetmap. Very cool. #devsummit - via @vtforester
  • @SharpGIS Dissin' the Flex folks. Too funny. I'm thinking Dodgeball game...flex team vs silverlight team. #devsummit - via @vtforester
  • Yay Jeremy! "Don't put ArcMap inside firefox" #devsummit #usability - via @bnoyle
  • For those interested in JS API 2 public beta...you need to get the bits from ESRI blogs. not integrated into resource centers yet #devsummit - via @bnoyle
  • Idea for next #DevSummit - API team should show nice, well designed workflow apps, and then go through how to build'em and release src - via @dbouwman
  • heard some people wondering what happened to gdb versioning. indeed no talk by ESRI at #devsummit -all web editing going directly to the gdb - via @oseidel
  • New Geolocator stuff is impressive. Configurable, Grammar-based with a plugin model.  Unicode/internationalised. Total rewrite. #DevSummit - via @geeknixta
  • Learn more about the forthcoming #ESRI ArcGIS Explorer Online from these #devsummit videos: http://bit.ly/bQ6mYW - via @bernszukalski
  • ArcGIS 10 Final release in June #devsummit - via @RealIdahoBoy
  • arcgis 10 prerelease available for all EDN #devsummit - via @Gazymodo
  • Everyone heard, ezre said Fedora 12 support on its way. #devsummit - via @cageyjames
  • @cageyjames fedora not at 10, that is post 10 #devsummit - via @spangrud
  • Arcgisserver 10 to get openid support in the future! #devsummit - via @RealIdahoBoy
  • #ArcGIS SDK for #iPhone: map layers, overlay graphics, search/id, locate address, collect data & tasks. #devsummit - via @dafkobyte
  • Disappointed that feature service web editing is only supported using SDE. Small-ish shops could really benefit from this. #devsummit - via @BrightRain
  • Last day of #devsummit. Thanks to everyone at #ESRI and I look forward to seeing you all next year. - via @calvinit21
  • at Palm Springs airport. goodbye #devsummit - via @Gazymodo

For newcomers to the series, here are my day 1, day 2day 3 and day 4 favorites.

Enjoy!

Tags: , , , , , ,

ESRI

My Favorite Tweets from the ESRI BPC / Devsummit - Day 4

by James Richards March 24, 2010

Presenting day 4 of my favorite tweets from the ESRI Business Partners Conference / Developer Summit. A lot more tweets coming through today with the #devsummit hash tag than there were the first two days with the #esri_bpc hash tag. My unscientific conclusion is that developers use Twitter more than business types.

  • @trbaker Where are your #Twitter followers? GeoTweeters: http://bit.ly/lscto #devsummit #gis #socialnetworking - via @geoinformacao
  • Sweet! We wom the mashup challenge! Plus big shout out to @dbouwman from #esri #devsummit - via @bnoyle
  • #ESRI #mashup challenge winners now online at http://bit.ly/5jG8Dz #DevSummit #esridevsummit - via @giseducation
  • Recently "mashup," now "cloud." Keywords we get to listen to for a while. #devsummit - via @RealIdahoBoy
  • David Chappell: "Startups love cloud platforms. They allow startups to fail fast and cheaply (or even free)." #devsummit - via @ChrisSpagnuolo
  • Hopefully Chappell will show how expensive windows azure is. #devsummit - via @cageyjames
  • #esri story on cloud computing is good, but still need more info on cost/time to scale and a move away from ELA only needed #devsummit - via @bnoyle
  • Spatial data stored in user tables, can be accessed via SQL #devsummit - via @TrippingTheBits
  • It is odd to me tho that complex maps perform better using SHP in AGS. #devsummit - via @kirrilian
  • The Flex editor is nice, but worry some will forget to use tools in the context of a workflow. Don't re-create ArcEditor in Flex! #DevSummit - via @dbouwman
  • New to ArcGIS 10: Query Layers = layers based on real SQL queries! #devsummit - via @TrippingTheBits
  • Sounds like FGDB API is still a ways off #devsummit - via @cageyjames
  • No support for Annotation, Relationships, Networks, Topologies, Representations, Terrains and Parcel Fabrics in FGDB API #devsummit - via @cageyjames
  • Sweet. Ed architecting a SQL compatible geocode soln. Off the cuff in response to question #devsummit - via @bnoyle
  • Browser usage in demos: Firefox = most, Chrome = a couple, IE = NONE. #devsummit - via @gadtweet
  • REST extension URLs: /serverUrl/exts/extName/extMethod #devsummit - via @TrippingTheBits
  • Woah, add AGS Inet connection to ArcMap, right-click, choose Edit Features, makes local copy, sync back to db #devsummit - via @TrippingTheBits
  • #devsummit ver 2 of esri #silverlight API built on #VS2010 and #SL4. New widgets for editing,time,and feature data editing in toolkit. - via @cfemmer
  • #devsummit @SharpGIS is spreading the #SL goodness. woot for binding and commanding! - via @jrockers
  • Playing with ArcGIS Explorer sdk...pretty awesome! A lot more control than I expected! #devsummit - via @NateStrout
  • iPhone SDK for AGS Server interesting. If only I had a Mac for development.... #devsummit - via @northpointgis
  • MS Surface demo, picking AGOL sources and dropping onto a map is slick! #DevSummit - via @geeknixta
  • #devsummit Iphone SDK will work with iPad and iTouch too. SDK assumes always on connection. - via @jshek

For newcomers to the series, here are my day 1, day 2 and day 3 favorites.

Enjoy!

Tags: , , , , , ,

ESRI

My Favorite Tweets from the ESRI BPC / Devsummit - Day 3

by James Richards March 23, 2010

Presenting day 3 of my favorite tweets from the ESRI Business Partners Conference / Developer Summit. I missed most of the morning due to being on a client site. But here are my faves from the afternoon.

  • @MapsRus I was in the Server session at the #ESRI_BPC - Nothing new in ADF for 10 . Only bug fixes. All but dead. #webADF #DevSummit - via @dbouwman
  • REST Server Object Extension sounds easy, implement the two method IRESTRequestHandler #devsummit - via @TrippingTheBits
  • At desktop add-in session at #devsummit. No more COM wireup with extensions. Fantastic! - via @BrightRain
  • #devsummit @ajhaddad just said three very exciting letters, "MEF" - via @jrockers
  • @rex_hansen showing us how to use Expression Blend to make a Silverlight app. Great starter session. API is nicely integrated. #DevSummit - via @geeknixta
  • At the Silverlight WPF session where Rex @rexhansen is showing the real power of Binding #devsummit - via @alpascual
  • @dbouwman just called me a troublemaker in his presentation. #sweet #devsummit - via @cageyjames
  • ArcGIS for Silverlight API 2.0 public beta coming in April. Supporting VS2010, Expression Blend 4, Silverlight 4, .NET 3.5 & 4. #DevSummit - via @geeknixta
  • Wow. Presenter says "filegdb faster on linux than sde". Goes against everything esri has said for years. #devsummit - via @geodatabase 
  • Videos of the #ESRI_BPC demos are now available. The ArcGIS Server on Amazon demo will be posted tomorrow. http://is.gd/aUZcV - via @ESRI_BPC
  • Where are the Avenue sessions? #devsummit - via @odoenet

Not too many tweets using the #esri_bpc hash tag any more. Most tweeps have moved over to #devsummit.

For newcomers to the series, here are my day 1 and day 2 favorites.

Enjoy!

Tags: , , ,

ESRI

Implementing Model-View-ViewModel with the Bing Maps (Virtual Earth) Silverlight Map Control

by James Richards September 28, 2009

Overview

I’ve been looking at the Bing Maps (Virtual Earth) Silverlight Map Control and thinking about how to use it in a Silverlight application that implements the Model-View-ViewModel pattern. If you’re not familiar with this pattern, check out Shawn Wildermuth’s MSDN Article Model-View-ViewModel in Silverlight 2 Apps.

I’ve created a simple proof of concept application that implements the pattern with two Views: a Map based View and a Data Grid based View. The application displays a map of well known surf spots in the Los Angeles area, along with some basic information about each spot in an accompanying data grid.

image

More...

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen | Modified by Mooglegiant
Creative Commons License This work is licensed under a Creative Commons Attribution 3.0 United States License.

Welcome

James Richards

Hi, I'm James Richards and I'm a GIS Programmer and Consultant from Los Angeles, California. I mostly write about developing spatial software with ESRI and Microsoft technologies. I can be reached through the contact form, or through my company Artisan Global LLC. Thanks for stopping by, I hope you find something helpful here.

Subscribe by RSS   Follow me on Twitter   Connect on Facebook   View my profile on LinkedIn


Amazon Associates

Some of my posts may contain Amazon Associates links. I only include these links when it makes sense within the context of the article. If you are in the market for one of these items, please consider clicking on an affiliate link to make your purchase. You still get the same great deal from Amazon and it will help me pay for hosting and bandwidth. Thanks!