Skip to main content

Create your first Google Maps application

In this article i will show you  the different steps to follow to create your first Google Maps application.
We will also demonstarte some usefull options that  give your application more flexibility and performance.

Creating the Project
Using Eclipse, create a new Android Project and name it  MapsDemo as  shown in Figure 1

Figure 1
Obtaining a Maps API Key
Before you integrate Google Maps in your Application, you need  to apply for a Free  Google Maps API Key.
To apply for key follow the steps  below.
You can refrence to Google's documentation for more  details.

  • First, find this file (debug.keystore)  and copy it (for simplicity) in c:\\Android(Create a folder named Andrioid under c:\\)
  • Extract the MD5 fingerpoint using the keytool.exe included with your JDK installation.You can find the keytool.exe under "C:\Program Files\Java\<JDK_version_number>\bin" folder.
keytool.exe -list -alias androiddebugkey -keystore "C:\android\debug.keystore" -storepass android -keypass android





Modify the  AndroidManifest.xml
Open The  AndroidManifest.xml file and add the following as a child of the <application> element.

<uses-library android:name="com.google.android.maps" />

You also need access to the Internet to retreive map tiles,so you must also request teh INTERNET permission.In the manifest file, add teh following as a child of the <manifest> element.

<uses-permission android:name="android.permission.INTERNET" />

The AndroidManifest.xml file :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="net.mapsdemo.android"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps" />
        <activity android:name=".MapsActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
    </application>
 <uses-permission android:name="android.permission.INTERNET" />
</manifest>
Dispalying the Map
To display the Google Maps in your Android application, modify the main.xml file located in the res/layout folder. You shall use the <com.google.android.maps.MapView> element to display the Google Maps in your activity. In addition, let's use the <RelativeLayout> element to position the map within the activity:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="9B:AE:A4:18:D6:16:C9:9D:FB:99:E2:84:6B:A8:13:F3"
/>
N.B : android:apiKey : you have to set Your Maps Key.
In the MapsActivity.java file, modify the class to extend from the  MapActivity  class, instead of the normal Activity class:

package net.mapsdemo.android;
import com.google.android.maps.MapActivity;


import android.app.Activity;
import android.os.Bundle;


public class MapsActivity extends MapActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }


 @Override
 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
  return false;
 }
}

That's it !! Your first Google Maps application looks like following :


Zoom, Sreet Maps ...
There's a very simple zom feature built into MapView class, which you can summon with setBuiltInZoomControls(boolean).Do this at the end of the onCreate() method.

MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);

You can also display the map in Street View, using the streetView(boolean) method.

mapView.setStreetView(true);



Comments

Popular posts from this blog

What You Must Know Before Establishing a Recovery Plan ?

In today's rapidly evolving digital landscape, organizations are increasingly adopting the zero trust model, primarily due to the expanding attack surface that leaves critical systems and data exposed. This shift is also fueled by the heightened sophistication of cyber-attacks, which have become more complex and harder to detect, surpassing traditional security measures. Additionally, the existing operating models within organizations are often inconsistent, typically characterized by distributed and siloed environments.    This fragmentation creates vulnerabilities and makes it challenging to implement uniform security protocols. The zero trust model addresses these challenges by assuming that threats exist both inside and outside the network, necessitating continuous verification of all users and devices. Its adoption represents a proactive stance in the ongoing battle against cyber threats, ensuring a more robust and resilient organizational security posture. The Evolution ...

A comprehensive guide to ransomware distribution in VMware environments

In a virtualized on-premises environment based on VMware, ransomware distribution scenarios can be somewhat unique due to the nature of virtualization technology. However, many of the traditional attack vectors still apply. Here are some ransomware distribution scenarios specific to a VMware-based virtualized environment: Phishing Attacks Targeting Administrators: Administrators with access to the VMware environment might receive phishing emails. If they fall for these and their credentials are compromised, attackers can gain access to the virtualized environment. Exploiting Vulnerabilities in VMware Software: If VMware software or the underlying operating system is not kept up-to-date with security patches, vulnerabilities can be exploited by attackers to deliver ransomware into the virtualized environment. Compromised Remote Management Tools: Tools used for remote management of the virtualized environment, such as vSphere, can be a target. If these tools are compromised, attackers ca...

Edge Computing Demystified Book

After a while I'm back and pleased  to share in this post my first book around Edge computing Technologies. Edge computing has been a very hot and interesting topic nowadays for communication service provider and Enterprise so far. Augmented Reality / Virtual Reality, Smart cities, Healthcare, industrial IoT and many others use cases require a change in the way we operate and host application in the cloud.  IA, Big Data and analytics are often used today to understand the behavior of the customer and even the health of services. Real-time and high throughput demand are the characteristic of the new business services. Edge computing technology promises to resolve different challenges and brings compute, storage and bandwidth close to the data source. I tried in ‘the Edge Computing Demystified’ book to explain Edge computing technology referring to different use cases from communication service provider and enterprise industry. I h...