Virtual Earth SDK Scripting Example
My Virtual Earth Map implements several key features of Microsoft's Virtual Earth SDK.
- Find Location
- Virtual Earth can find locations and center the map with a push-pin marker at that point.
- Enter a place-name or address (street, city, st/country) in the From or To field and click the Find button. Virtual Earth automatically adjusts the zoom level to fit the type of location being displayed (for example, a building/street address or a city.)
- Find Latitude/Longitude
- Enter a latitude and longitude in the Lat,Lng field to center the map at that location. The current zoom level will be preserved.
- Get Directions
- Enter both From and To addresses, then click the Directions button to query Virtual Earth's database for driving instructions from one place to the other. The results are displayed in a sidebar box. (Note, it may take some time for long routes to be returned.)
- Get Latitude/Longitude
- When the map is moved, the latitude and longitude of the current center of the map are displayed in the Lat,Lng field.
- Get/Set Zoom
- When the map is zoomed in or out, the current numeric zoom level is displayed in the Zoom dropdown. Selecting a level from the dropdown sets the map to that zoom.
In addition to demonstrating SDK functions, my example includes other features to enhance use of the Virtual Earth map.
- Map Size
- The default method sets the map size to fit current browser window and resizes the map when the user resizes the window. The map can be set to a specific pixel size using the query-string initialization methods described below.
- Query-String Initialization
- My example contains script to allow initialization of the map using query-string parameters appended to the URL for the page. Map size, location, zoom level, From-To routing and even bird's eye views can be set automatically when the page loads. Links created in this manner can be placed on Web pages or in email to share specific map views with others.
- A link can be created by setting the map to the desired location and view, then clicking the Create URL button. The hyperlink text will be displayed in the URL field from which it can be copied and pasted for further use.
- See the Query-String Parameter Reference for more details and examples.