ã¯ããã¦ã®Bing Maps Silverlight Control
Download Bing Maps Silverlight Control SDK from Official Microsoft Download Center
Silverlightç¨ã®BingMapsã³ã³ããã¼ã«ããªãªã¼ã¹ãããã®ã§ãåå¼·ãã¦ãç°¡åãªãµã³ãã«ãä½æãã¦ã¿ã¾ãã
ãé¡ã¯ã³ã¬ã
âããã¹ãããã¯ã¹ã«ãã¼ã¯ã¼ã(ä¾ãã°æ±äº¬ã¿ã¯ã¼ã¨ã)ãå
¥åãããããã®å ´æã表示ãããã¨ããåç´ãªã®ã
UIã¯Silverlighã§ä½æããµã¼ãã¼å´ã¯ãã¼ã¯ã¼ããåãåã£ã¦ã¸ãªã³ã¼ããè¿ããå¾ã¯ããã®ã¸ãªã³ã¼ããBingMapsã«æ¸¡ãã ãã§ãã
<UserControl xClass="BingMapsSample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlnsx="http://schemas.microsoft.com/winfx/2006/xaml" xmlnsd="http://schemas.microsoft.com/expression/blend/2008" xmlnsmc="http://schemas.openxmlformats.org/markup-compatibility/2006" mcIgnorable="d" xmlnsm="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl" d:DesignHeight="300" d:DesignWidth="400"> <Grid xName="LayoutRoot" Background="White"> <GridRowDefinitions> <RowDefinition Height="Auto"> <RowDefinition Height="*"> </GridRowDefinitions> <GridColumnDefinitions> <ColumnDefinition> <ColumnDefinition Width="Auto"> </GridColumnDefinitions> <TextBox Name="address" GridRow="0"></TextBox> <Button GridRow="0" GridColumn="1" Content="Go" Click="Button_Click"> <mMap Name="map" GridRow="1" GridColumnSpan="2" CredentialsProvider="key" Mode="Aerial" > </Grid> </UserControl>
âã¾ãã¯ãããã¹ãããã¯ã¹ã¨ãã¿ã³ã¨BingMapsããç¡ãææãUIã
CredentialsProvider="key"
âkeyã¯åèªã§å ¥æãã¦ãã ããã
次ã«ãUIã®ã³ã¼ãé¨åã
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Maps.MapControl.Design; using System.Json; namespace BingMapsSample { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { WebClient client = new WebClient(); string url = "http://localhost:52378/GeoCode/Get/" + Uri.EscapeUriString(address.Text); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); client.DownloadStringAsync(new Uri(url), null); } void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) return; var result = e.Result; var val = JsonValue.Parse(result); var coordinates = val["Placemark"][0]["Point"]["coordinates"]; map.SetView(new Microsoft.Maps.MapControl.Location(coordinates[1], coordinates[0]), 20); } } }
å ¥åãããã¼ã¯ã¼ããåå¾ãã¦ãGeocodeControllerã®Getã¡ã½ãããå¼ã³åºãã¦ãæ»ã£ã¦ããçµæããã¸ãªã³ã¼ããåå¾ããã ããGeocodeControllerã¯ãASP.NET MVCã®ã³ã³ããã¼ã©ã§ããããä½ããã®ã§ãã
ã§ããã®ã³ã³ããã¼ã©ã
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Ajax; using System.Net; using System.IO; using System.Text; namespace BingMapsSample.Web.Controllers { public class GeocodeController : Controller { // // GET: /Geocode/ public ActionResult Index() { return View(); } public ActionResult Get() { const string URL = "http://maps.google.com/maps/geo?q="; WebClient client = new WebClient(); string url = URL + Uri.EscapeUriString(RouteData.Values["id"].ToString()); var stream = client.OpenRead(new Uri(url)); var text = new StreamReader(stream, Encoding.UTF8).ReadToEnd(); return Content(text); } } }
maps.google.comã«ã¢ã¯ã»ã¹ããã ãã§ããã
ããã§ç»åã®ãããªãµã³ãã«ã®å®æã§ããè¨äºã«ããã大ãããã¨ããã¾ããããä¹ ã ã®Silverlightã ã£ãããä¸æ £ããªASP.NET MVCã ã£ãããåãã¦ã®JsonValueã ã£ããã§ãæªæ¦è¦éãã¾ããã(^^;