Searching for an address

Have you ever wondered how you could search for a specific address in a map and obtain its coordinates?

In this case, GeocodeQuery is the way to go! Let’s start ūüôā

First of all, you need to declare a String containing the address you want to look for:

String searchTerm("Redmond");

Then, declare a boolean that will be set to true when the route is being searched, otherwise false:

private bool _isRouteSearch = false;

Now it’s time to write the rest of the code (don’t worry, I’ll explain right after what it currently does):

MyGeocodeQuery = new GeocodeQuery();
MyGeocodeQuery.SearchTerm = searchTerm;
MyGeocodeQuery.GeoCoordinate = MyCoordinate == null ? new GeoCoordinate(0, 0) : MyCoordinate; MyGeocodeQuery.QueryCompleted += GeocodeQuery_QueryCompleted;

The code itself looks quite straightforward. The QueryAsync() is launched after the SearchTerm has been set, together with the function to launch when the Query gets completed (possibly a group of markers marking the locations searched) and the “start coordinates” of the query have been set with the phone current location.

The result of the GeocodeQuery is a list of MapLocations representing the hits matching the SearchTerm of the query. Each MapLocation has a GeoCoordinate for positioning the location on the map, as well as detailed LocationInformation with name, description and MapAddress of the location. The event handler GeocodeQuery_QueryCompleted is called both when searching the map for a keyword and when searching for a route. The route specific part is explained later on. Here the search results are stored to be later used for drawing map markers.


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.