Integrating maps

In Chapter 8, Mastering Intents – A Walkthrough, we use an intent aiming to redirect us to the google map application at a specific address. In this recipe, we will see all the options available with the Google Map and Google Street Intents.

Getting ready

Create a new project named GoogleMapsIntents.

How to do it...

  1. Drag and drop three different buttons in your application.
  2. Map the newly created three buttons on press events with the following three code examples:

    Button 1:

    var geoUriToMontreal = Android.Net.Uri.Parse ("geo: 45.5088400, -73.5878100?z=4x");
    var mapIntentToMontreal = new Intent (Intent.ActionView, geoUriToMontreal);
    StartActivity (mapIntentToMontreal);

    Button 2:

    var geoUriTotheEiffelTower = Android.Net.Uri.Parse ("geo:0,0?q=Eiffel tower&z=2x");
    var mapIntentToTheEiffelTower = new Intent (Intent.ActionView, geoUriTotheEiffelTower);
    StartActivity (mapIntentToTheEiffelTower);

    Button 3:

    var streetViewUriToCambridge = Android.Net.Uri.Parse ("google.streetview:cbll=42.374260,-71.120824,90,0,1.0");
    var streetViewIntentToCambridge = new Intent (Intent.ActionView, streetViewUriToCambridge);
    StartActivity (streetViewIntentToCambridge);
  3. Start your application. Every time you press a button, the Google Map or the Google Street View application will open to a different location.

How it works...

As the working principles of intents have been explained in Chapter 8, Mastering Intents – A Walkthrough, I will only go through the arguments and options you can use with the Google Map and Google Street intents:

  • geo:latitude,longitude: This is the classic and oldest way to use the Google Map Intent. It will open Google Maps on a latitude, longitude location.
  • geo:latitude,longitude?z=zoomlevel: You can combine the previous latitude, longitude with a zoom level. Usable zoom levels are 1.0 for normal zoom, 2.0 for 2.x zoom, 3.0 for 4.x zoom, and so on.
  • geo:0,0?q=any+search: This particular combination, with longitude and latitude set to zero and followed by the ?q= value will allow you to use Google Map Intents as you use the Google Maps website. For example, you search for "McDonads near New york city" or complete addresses such as "1 Rue de la République, Paris".

    The Google Street View intent slightly differs as it has to start with "google.streetview:cbll=" and then arguments have to be placed as follows:

    Latitude, longitude, yaw, pitch, and zoom.

The two new arguments, yaw and pitch, are the horizontal orientations in degrees from north and the vertical orientation (90% to the sky, -90% to the floor).

See also

If you wish to modify the map's look and feel for a deeper integration with your application, you can take a look at http://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/part_2_-_maps_api/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.136.235