SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
ASP.NET, VB.NET, Microsoft .NET Framework, Microsoft Visual Studio, Windows Forms, Controls and more Tutorials and Articles for Programmers

Microsoft MapPoint Web Service Version 3.5 ile Harita Üzerinde Adres Görüntüleme

Microsoft MapPoint Web Service kullanarak harita üzerinde uygulamalar geliştirebilirsiniz. Bu makalede MapPoint ile uygulama geliştirmeye giriş olarak harita üzerinde bir nokta görüntülemek üzerinde duracağız.MapPoint Web Service hizmetlerinden faydalanabilmek için belirli bir ücret ödemek zorundasınız. Ancak https://mappoint-css.partners.extranet.microsoft.com/MwsSignup/Eval.aspx adresinden dolduracağınız form ile başvuruda bulunarak 45 günlük MapPoint Web Service Developer Account adı altında geçici bir account'a sahip olabilir ve bu account yardımı ile development süreniz boyunca MapPoint Web Service hizmetlerinden yararlanabilirsiniz.





MapPoint Web Service ile geliştireceğiniz uygulamalarınızda belirtilen web servisini projenize web referansı olarak eklemeniz gerekmekte.

Eklenmiş bu web referansı ASP.NET code behind sayfasında en başta Imports ile aşağıdaki gibi kullanabilirsiniz.

    Imports MapPoint.net.mappoint.staging

Bu yazının konusu olan örnek uygulamada Amerika Birleşik Devletleri üzerinde bir noktanın harita üzerinde görüntülenmesini göreceğiz. Görüntülemek istediğimiz adresimiz "Huntington Beach, CA" olsun.

ASP.NET uygulaması geliştirdiğimizi varsayarak web formumuz üzerinde bir Image kontrolümüz ve bir de Button kontrolümüz olduğunu varsayalım. Butona bastığımızda adresimizi Image kontrolümüz üzerinde görüntüleyelim.

Butonumuzun Click event'i için çalışmasını istediğimiz kodu aşağıdaki gibi oluşturalım.

 

Private Sub buttonShowOnMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonShowOnMap.Click

' MapPoint WEB Service Authentication
Dim MapPointWebServiceCredentials As New NetworkCredential("EvaluationAccountUserName", "EvaluationAccountUserPassword")

' Prepare necessary MapPoint Services

Dim renderService As New RenderServiceSoap
renderService.Credentials = MapPointWebServiceCredentials

Dim findService As New FindServiceSoap
findService.Credentials = MapPointWebServiceCredentials


' Point of Interest

Dim pointSpec As New FindSpecification
pointSpec.DataSourceName = "MapPoint.NA"
pointSpec.InputPlace = "Huntington Beach, CA"

Dim findPointResults As New FindResults

findPointResults = findService.Find(pointSpec)


' Pushpins

Dim myPushpins(0) As Pushpin
myPushpins(0) = New Pushpin

myPushpins(0).IconDataSource = "MapPoint.Icons"
myPushpins(0).IconName = "1"
myPushpins(0).Label = "Huntington Beach, CA"
myPushpins(0).LatLong = findPointResults.Results(0).FoundLocation.LatLong


' Views

Dim viewByHW As New ViewByHeightWidth
viewByHW = findPointResults.Results(0).FoundLocation.BestMapView.ByHeightWidth

Dim mView(0) As MapView
mView(0) = viewByHW


' MapSpecification

Dim mapSpecification As New MapSpecification
mapSpecification.DataSourceName = "MapPoint.NA"
mapSpecification.Pushpins = myPushpins
mapSpecification.Views = mView

mapSpecification.Options = New MapOptions
mapSpecification.Options.ReturnType = MapReturnType.ReturnUrl
mapSpecification.Options.Format = New ImageFormat
mapSpecification.Options.Format.Height = 180
mapSpecification.Options.Format.Width = 180


' Get Map
Dim mapImage() As MapImage
mapImage = renderService.GetMap(mapSpecification)

Image1.ImageUrl = mapImage(0).Url


End Sub

 

Kodu incelediğimizde göreceğiz ki oluşturduğumuz MapPointWebServiceCredentials objesi ile MapPoint WEB Service için gerekli Authentication'ı sağlamış oluyoruz. NetworkCredential 'ı oluştururken gerekli olan UserName ve Password başvuruda bulunduğunuz MapPoint Web Service Developer Account ile size sağlanacaktır.

' MapPoint WEB Service Authentication
Dim MapPointWebServiceCredentials As New NetworkCredential("EvaluationAccountUserName", "EvaluationAccountUserPassword")

FindServiceSoap ile haritada kullanacağımız noktalar için arama fonksiyonlarını sağlıyoruz. RenderServiceSoap ile de bu noktaların harita haline getirilmesi ile ilgili işlemleri gerçekleştiriyoruz.

Dim renderService As New RenderServiceSoap
renderService.Credentials = MapPointWebServiceCredentials

Dim findService As New FindServiceSoap
findService.Credentials = MapPointWebServiceCredentials

Göreceğiniz üzere her bir servis için (RenderServiceSoap ve FindServiceSoap) Credential tanımlamamız gerekiyor.

 

Ardından aradığımız noktayı ifade eden pointSpec objesini yani FindSpecification class'ının bir örneğini oluşturuyor ve gerekli bilgileri bu objenin property'leri olarak atıyoruz.

' Point of Interest

Dim pointSpec As New FindSpecification
pointSpec.DataSourceName = "MapPoint.NA"
pointSpec.InputPlace = "Huntington Beach, CA"

Dim findPointResults As New FindResults

findPointResults = findService.Find(pointSpec)

Aradığımız noktanın özelliklerini belirttikten sonra dönecek olan sonuçları bir dizide tutmak için FindResults tipinde bir dizi oluşturuyoruz. FindServiceSoap class'ının instance'ı olarak oluşturduğumuz findService objesinin Find metodu ile de aramamızı gerçekleştiriyoruz. Bu aramadan dönen sonuçları findPointResults objesinde saklamış olduk.

 

Artık haritamızı oluşturmak için kodlarımızı yazabiliriz. 

Pushpin objeleri ile haritada işaretlemek istediğimiz noktaları belirtiyoruz. Örnekte işaretlemek istediğimiz tek nokta aramamızın sonucu dönen ilk nokta olsun. Bu da findPointResults.Results(0) içinde saklıdır. LatLong özelliği Latitude ve Longitude anlamlarına yani enlem ve boylam anlamına gelmektedir. Böylece işaretlemek istediğimiz noktanın enlem ve boylamını elde etmiş ve bunu Pushpin dizisinde saklamış olduk.

' Pushpins

Dim myPushpins(0) As Pushpin
myPushpins(0) = New Pushpin

myPushpins(0).IconDataSource = "MapPoint.Icons"
myPushpins(0).IconName = "1"
myPushpins(0).Label = "Huntington Beach, CA"
myPushpins(0).LatLong = findPointResults.Results(0).FoundLocation.LatLong

Ardından bir View objesi oluşturuyoruz.

' Views

Dim viewByHW As New ViewByHeightWidth
viewByHW = findPointResults.Results(0).FoundLocation.BestMapView.ByHeightWidth

Dim mView(0) As MapView
mView(0) = viewByHW

Ve haritamızın özelliklerini oluşturuyoruz. Pushpins ve Views objeleri burada haritamızın özelliklerini toparlayan MapSpecification objesi ile eşleştiriliyorlar.

' MapSpecification

Dim mapSpecification As New MapSpecification
mapSpecification.DataSourceName = "MapPoint.NA"
mapSpecification.Pushpins = myPushpins
mapSpecification.Views = mView

mapSpecification.Options = New MapOptions
mapSpecification.Options.ReturnType = MapReturnType.ReturnUrl
mapSpecification.Options.Format = New ImageFormat
mapSpecification.Options.Format.Height = 180
mapSpecification.Options.Format.Width = 180

En son adım olarak MapImage'ımız RenderServiceSoap class'ının objesi olan renderService tarafından GetMap metodu ile oluşturuluyor.

' Get Map
Dim mapImage() As MapImage
mapImage = renderService.GetMap(mapSpecification)

Ve ASP.NET formumuz üzerinde yeralan Image kontrolümüz RenderServiceSoap objemizin GetMap metodu ile elde ettiğimiz MapImage nesnemiz ile ilişkilendirilerek haritayı görüntülemesi sağlanıyor.

Image1.ImageUrl = mapImage(0).Url

Yukarıdaki kod parçası ile elde ettiğimiz harita görüntüsünü aşağıda görebilirsiniz.

MapPoint Sample

Visual Studio


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.