Skip to main content

How to use Bing Maps v7

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.

Comments

Popular posts from this blog

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Run native .NET application in Docker (.NET Framework 4.6.2)

Scope
The main scope of this post is to see how we can run a legacy application written in .NET Framework in Docker.

Context
First of all, let’s define what is a legacy application in our context. By a legacy application we understand an application that runs .NET Framework 3.5 or higher in a production environment where we don’t have any more the people or documentation that would help us to understand what is happening behind the scene.
In this scenarios, you might want to migrate the current solution from a standard environment to Docker. There are many advantages for such a migration, like:

Continuous DeploymentTestingIsolationSecurity at container levelVersioning ControlEnvironment Standardization
Until now, we didn’t had the possibility to run a .NET application in Docker. With .NET Core, there was support for .NET Core in Docker, but migration from a full .NET framework to .NET Core can be costly and even impossible. Not only because of lack of features, but also because once you…