Windows Mobile Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 3 November 2011

How to use Bing Maps v7

Posted on 08:12 by Unknown
In ziua de azi, de la o poza sau un document pana la un colet trimis prin curier sau localul la care ai iesit aseara poate sa fie track-uita pe harta. Aceste harti sunt oferite gratis (Bing, Maps, Google Maps etc), iar singurul lucru pe care trebuie sa il cunoastem sunt coordonate GPS.
Un utilizator poate sa foloseasca aceste harti fara nici o problema, iar cea mai mare parte din persoanele care iti acceseaza web situl nu o sa aibe probleme cu folosirea unei harti. Mai jos o sa discutam despre cum putem sa integram si sa folosim Bing Maps in web situl nostru.
Exista mai multe versiuni de API pentru Bing Maps, ultima versiune (vs 7.0) a fost regandita de la 0 si a devenit extrem de usor de folosit. O sa ne uitam peste versiunea 7.0, care este integrata in totalitate cu ajax.
Tot setup-ul se face din java script. Primul pas este sa ne cream un obiect de tip Map si sa specificam zona de pe pagina unde sa apara:
<head>
...
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('mapDiv'), null);
}
</script>
</head>
<body onload="getMap();">
<div id='mapDiv' style="position:relative; width:600px; height:500px;"></div>
</body>
In momentul de fata avem harta afisata, dar avem un mesaj de eroare cane ne indeamna sa folosim credentiale valide. Harta se poate folosii si asa, doar ca banerul cu mesajul de eroare nu o sa il putem sterge. Ca sa scapam de el trebuie sa ne inregistram la adresa http://www.microsoft.com/maps/developers/web.aspx .
O sa primim o cheie unica pe care o sa o setam cand cream un nou obiect de tip map.
map = new Microsoft.Maps.Map(document.getElementById('myMap'),
{
credentials: '[CheieUnica]'
});
Avem harta pe pagina noastra, putem sa facem zoom in si zoom out si sa ne pozitionam oriunde vrem pe harta.
Urmatorul pas este sa adaugam cateva puncte( pushpin-uri). Ce este important la aceste pushpin-uri sunt coordonatele GPS. In exemplul de mai jos, unul din pushpin-uri va puncta spre o locatia data, iar celalat spre centrul hartii.
function updatePushpinLocation()
{
var pushpinLocatieData= new Microsoft.Maps.Pushpin(map.getCenter(), null);
map.entities.push(pushpinLocatieData);
pushpinLocatieData.setLocation(new Microsoft.Maps.Location(48, 52));

var pushpinCentruHarta= new Microsoft.Maps.Pushpin(map.getCenter(), null);
map.entities.push(pushpinCentruHarta);
}
In cazul in care pe evenimentul de click la un pushpin dorim sa afisam un info box, putem sa folosim obiecte de tip Infobox in loc de pushpin, iar de restul de ocupa API-ul de la Bing Maps. Fiecare infobox poate sa aibe un titlu si o descriere care sa se afiseze cand se da click pe acesta. Este bine de stiut ca putem insera si cod html, doar ca atunci trebuie sa folosim metoda setHtmlContent a obiectului Infobox.
var infoboxOptions = { title:'Titlu', description:'Descriere ...'};
var pushpin = new Microsoft.Maps.Infobox(map.getCenter(), infoboxOptions );
map.entities.push(pushpin);
Pe fiecare pushpin sau infobox putem sa adaugam evenimente precum click, etc.
pushpinClick= Microsoft.Maps.Events.addHandler(pushpin, 'click', clickEventInfo);
clickEventInfo= function (e) { alert("Click"); }
Orice eveniment pe harta poate sa fie prins si manipulat. In cazul in care dorim sa stergem toate punctele de pe harta este nevoie sa apelam functia map.entities.clear().
Unele browsere ne permit sa accesam locatia GPS a aparatului si sa localizam userul pe harta. Trebuie sa tinem cont ca utilizatorul o sa fie intrebat daca face share la aceasta informatie de catre brower.

var geoLocationProvider = new Microsoft.Maps.GeoLocationProvider(map);
geoLocationProvider.getCurrentPosition();
Ce mi s-a parut cel mai interesant am lasat la sfarsit. Putem sa incarcam sau sa folosim module scrise de alte persoane pentru a personaliza harta sau sa extindem functionalizatiile. Inregistrarea unui modul se face prin intermediul comenzii Microsoft.Maps.registerModule. Build-in putem sa incarcam module precum:
  • Traffic Module
  • Clustering Module
  • Direction Module
  • VenueMaps Module
  • Navigation Bar Module
Cel mai interesant modul mi se pare ca este Clustering Module, care ne permite sa grupam 1..n locatii pe harta sunt prea apropiate. Pe codeplex, puteti sa gasiti o colectie de module destul de utile bingmapsv7modules.codeplex.com.
O alta functionalitate este cautare pe harta. Tot ce trebuie sa facem este sa apelam un serviciu REST oferit de Bing Maps.

map.getCredentials(function(credentials) {
var searchRequest = 'http://dev.virtualearth.net/REST/v1/Locations/ClujNapoca?output=json&jsonp=SearchServiceCallback&key=' + credentials;
var mapscript = document.createElement('script');
mapscript.type = 'text/javascript';
mapscript.src = searchRequest;
document.getElementById('SDKmap').appendChild(mapscript);
});
Puteti sa gasiti exemple de cod in urmatoarea locatie http://www.bingmapsportal.com/ISDK/AjaxV7.

Enjoy.
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in ajax, bing maps v7, java script, tutorial | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Service Bus Topic - Automatic forward messages from a subscription to a topic
    Windows Azure Service Bus Topic is a service that enables us to distribute the same messages to different consumers without having to know e...
  • Patterns in Windows Azure Service Bus - Message Splitter Pattern
    In one of my post about Service Bus Topics from Windows Azure I told you that I will write about a post that describe how we can design an a...
  • CDN is not the only solution to improve the page speed - Reverse Caching Proxy
    I heard more and more often think like this: “If your website is to slow, you should use a CDN.” Great, CDN is THE solution for any kind of ...
  • E-Learning Vendors Attempt to Morph Mobile
    The sign should read: " Don't touch! Wet Paint !" I had a good chuckle today after receiving my latest emailed copy of the eLe...
  • Content Types - Level 6: Rich Media
    Level 6: Rich Media NOTE: This is part 7 of 7 and the conclusion of this continuing series; please see earlier posts for more background inf...
  • Publishing our CellCast Widget for iPad
    The rush has been on this week as our development team worked to design a new version of our CellCast Widget specifically for Apple's up...
  • Content Types - Level 5: Courseware
    Level 5: Content and Courseware NOTE: This is part 6 of 7 in a continuing series; please see earlier posts for more background information. ...
  • SQL - UNION and UNION ALL
    I think that all of us used until now UNION in a SQLstatement. Using this operator we can combine the result of 2 queries. For example we wa...
  • Cum sa salvezi un stream direct intr-un fisier
    Cred ca este a 2-a oara când întâlnesc aceasta cerința in decurs de câteva săptămâni. Se da un stream și o locație unde trebuie salvat, se c...
  • Content Types - Level 4: Reference
    Level 4: Reference Materials & Static Content NOTE: This is part 5 of 7 in a continuing series; please see earlier posts for more backgr...

Categories

  • .NET
  • .NET nice to have
  • #if DEBUG
  • 15 iunie 2011
  • 15 octombrie 2011
  • 2011
  • abstracta
  • action
  • adaugare
  • ajax
  • Amsterdam
  • Android
  • aplicatii
  • App Fabric
  • Apple iSlate
  • array
  • as
  • ASP.NET
  • AsReadOnly
  • Assembly comun
  • async
  • Asynchronous programming
  • asyncron
  • Autofac
  • AutoMapper
  • az
  • Azure
  • Azure AppFabric Cache
  • Azure backup solution
  • Azure Storage Explorer
  • azure. cloud
  • backup
  • BCP utility
  • bing maps v7
  • BitArray
  • BlackBerry
  • blob
  • BlobContainerPublicAccessType
  • breakpoint
  • bucuresti
  • C#
  • cache
  • CallerMemberName
  • CellCast
  • Certificate
  • CES
  • change
  • ChannelFactory
  • clasa
  • classinitialize
  • clean code
  • click event
  • close
  • Cloud
  • Cluj
  • cluj-napoca
  • Code contracts
  • code retrat
  • codecamp
  • CollectionAssert
  • Compact Edition
  • compara
  • Comparer T .Default
  • CompareTo
  • comparison
  • comunitate
  • concurs
  • Conditional attribute
  • configurare
  • connection string
  • container
  • content type
  • control
  • Convert
  • convertAll
  • convertor
  • cross platform
  • CRUD
  • css
  • custom properties
  • custom request
  • DACPAC
  • Daniel Andres
  • data sync service
  • database
  • date time
  • datetime
  • debug
  • default
  • delegate
  • dependency injection
  • deploy
  • DeploymentItem
  • design patterns
  • Dev de Amsterdam
  • development stoage
  • dictionary
  • diferente
  • digging
  • director
  • Directory.Exist
  • disable
  • dispatcher
  • dispose
  • dropdown
  • dynamic
  • EF
  • email
  • encoding
  • entity framework
  • enum
  • enumerable
  • Environment.NewLine
  • error
  • error 404
  • error handling
  • eveniment
  • event
  • ews
  • excel
  • exception
  • exchange
  • exita
  • explicit
  • export
  • extension
  • field
  • File.Exist
  • finalize
  • fire and forget
  • Fluent interface pattern
  • format
  • func
  • GC.SuppressFinalize
  • generic
  • getdirectoryname
  • globalization
  • gmail
  • hackathon
  • Hadoop
  • handle
  • HTML
  • html 5
  • Html.ActionLink
  • http://www.blogger.com/img/blank.gif
  • HttpModule
  • IComparable
  • IE
  • ienumerable
  • IIS
  • image
  • implicit
  • import
  • int
  • internationalization
  • Internet Explorer
  • interop
  • Ioc
  • IP Filter
  • iPhone
  • iQuest
  • IStructuralEquatable
  • ITCamp
  • itspark
  • java script
  • javascript
  • July 2012
  • KeyedByTypeCollection
  • KeyNotFoundException
  • Kinect SDK
  • lambda expression
  • LightSwitch Microsoft Silverlight
  • linq
  • list
  • lista
  • lista servicii
  • liste
  • Live Connect
  • Live ID
  • load
  • localization
  • lock
  • m-learning
  • MAC
  • Mango
  • map
  • mapare
  • mapare propietati
  • messagequeue
  • meta properties
  • method
  • MethodImpl
  • Metro App
  • Microsoft
  • Microsoft Sync Framework
  • mlearning
  • mlearning devices
  • Mobile Apps
  • mobile in the cloud
  • mobile learning
  • mobile services
  • Mobile Web
  • mongoDb
  • monitorizare
  • msmq
  • multitasking
  • MVC
  • MVC 3
  • MVVM
  • namespace
  • nextpartitionkey
  • nextrowkey
  • Ninject
  • nivel acces
  • no result
  • normalize
  • nosql
  • null expcetion
  • null object pattern
  • NullReferenceException
  • OAuth API
  • office
  • offline
  • Open ID
  • openhackeu2011
  • operations
  • operator
  • optimization
  • option
  • outputcache
  • OutputCacheProvider
  • override
  • paginare
  • pagination
  • path
  • persistare
  • Portable Library tool
  • Post event – CodeCamp Cluj-Napoca
  • predicate
  • predictions
  • prezentare
  • process
  • proiect
  • property
  • propietati
  • query
  • ReadOnlyCollection
  • ReadOnlyDictionary
  • referinta
  • reflection
  • remote
  • reply command
  • request
  • request response
  • resouce
  • REST
  • REST Client
  • RESTSharp
  • ronua
  • rss
  • rulare
  • salvare in fisier
  • sc
  • schimbare timp
  • select
  • select nodes
  • send
  • serializare
  • serialization
  • Server.Transfer. Resposen.Redirect
  • service bus
  • ServiceBase
  • servicecontroller
  • sesiune
  • session
  • Session_End
  • Session_Start
  • setup
  • Sibiu
  • signalR
  • Silverlight
  • sincronizare
  • Single Responsibility Principle
  • SkyDrive
  • skype
  • smartphones
  • smtp
  • Snapguide
  • sniffer
  • socket
  • solid
  • spec#
  • sql
  • Sql Azure
  • SQL CE
  • sql server 2008 RC
  • SRP
  • startuptype
  • stateful
  • stateless
  • static
  • stergere
  • store
  • store procedure
  • stream
  • string
  • string.join
  • struct
  • StructuralEqualityComparer
  • submit
  • switch
  • Symbian
  • Synchronized
  • system
  • tabele
  • table
  • techEd 2012
  • tempdata
  • test
  • testcleanup
  • testinitialize
  • testmethod
  • thread
  • timer
  • ToLower
  • tool
  • tostring
  • Total Cost Calculator
  • trace ASP.NET
  • transcoding
  • tuplu
  • tutorial
  • TWmLearning
  • type
  • unit test
  • unittest
  • UrlParameter.Optional
  • Validate
  • validation
  • verificare
  • video
  • view
  • ViewBag
  • virtual
  • visual studio
  • VM role
  • Vunvulea Radu
  • wallpaper
  • WCF
  • WebBrower
  • WebRequest
  • where clause
  • Windows
  • windows 8
  • Windows Azure
  • Windows Azure Service Management CmdLets
  • windows live messenger
  • Windows Mobile
  • Windows Phone
  • windows service
  • windows store application
  • Windows Task
  • WinRT
  • word
  • workaround
  • XBox
  • xml
  • xmlns
  • XNA
  • xpath
  • YMesseger
  • Yonder
  • Zip

Blog Archive

  • ►  2013 (139)
    • ►  November (17)
    • ►  October (12)
    • ►  September (10)
    • ►  August (7)
    • ►  July (8)
    • ►  June (15)
    • ►  May (12)
    • ►  April (17)
    • ►  March (16)
    • ►  February (9)
    • ►  January (16)
  • ►  2012 (251)
    • ►  December (9)
    • ►  November (19)
    • ►  October (26)
    • ►  September (13)
    • ►  August (35)
    • ►  July (28)
    • ►  June (27)
    • ►  May (24)
    • ►  April (18)
    • ►  March (17)
    • ►  February (20)
    • ►  January (15)
  • ▼  2011 (127)
    • ►  December (11)
    • ▼  November (20)
      • What is the difference between Globalization, Loca...
      • Detecting Session Timeouts
      • ViewBag don't contains items which are set in the ...
      • Why to use/not to use Server.Transfer
      • When Session_End is called
      • #IF DEBUG can be replaces with Conditional attribute
      • Prezentare CODECAMP - Windows Phone: multitasking ...
      • DateTime.AddDays(x)
      • No connection could be made because the target mac...
      • Mango ce versiune de Windows Phone 7 este?
      • What to use? Event or delegate?
      • Windows Phone 7.5( Mango) support SQL CE
      • Visual Studio 2010 extensions
      • How to store an array of booleans in a int
      • How to manualy set the location from where a contr...
      • Evenimente IT de toamnă - CodeCamp și ITSpark
      • ToLower - optimization
      • How to use Bing Maps v7
      • .NET - Nice to have
      • EWS - Reply command - odd behavior
    • ►  October (8)
    • ►  September (8)
    • ►  August (8)
    • ►  July (10)
    • ►  June (5)
    • ►  May (8)
    • ►  April (9)
    • ►  March (14)
    • ►  February (20)
    • ►  January (6)
  • ►  2010 (26)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (4)
    • ►  March (1)
    • ►  February (1)
    • ►  January (14)
Powered by Blogger.

About Me

Unknown
View my complete profile