Learn Python


Click to Learn Python3
Showing posts with label google map. Show all posts
Showing posts with label google map. Show all posts

Sunday, July 31, 2011

Creating keystore and google api key for android google maps

Open the command prompt and follow the steps

D:\android-sdk-windows-1.6_r1\tools>keytool -genkey -v -keystore projectkey.keystore -alias aliasname -keyalg RSA -keysize 2048 -validity 15000
Enter keystore password: ------------
What is your first and last name?
[Unknown]: ------------
What is the name of your organizational unit?
[Unknown]: ------------
What is the name of your organization?
[Unknown]: ------------
What is the name of your City or Locality?
[Unknown]: ------------
What is the name of your State or Province?
[Unknown]: ------------
What is the two-letter country code for this unit?
[Unknown]: ------------

D:\android-sdk-windows-1.6_r1\tools>keytool -list -alias aliasname -keystore projectkey.keystore
Enter keystore password:
aliasname, Dec 7, 2010, PrivateKeyEntry,
Certificate fingerprint (MD5): CA:CF:AA:0E:5A:2B:88:C8:64:F1:FA:F7:29:21:50:FF

Using your Certificate fingerprint (MD5) get google api key from this site
http://code.google.com/android/maps-api-signup.html

Thursday, April 21, 2011

Google map example in android with info window (Popup) and multiple markers and zoom controls

Through this application we can populate a google map with the info window, zoom controls and marker features. The image of the running application is shown below



First of all, we can run the application with the google api sdk only, we can use from API level 3, but the Google api sdk should be used to run the application.

Custom Linear layout is used on this application




LocationViewers.java

package com.icons.draw.view;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ZoomControls;

import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.icons.draw.R;

public class LocationViewers extends LinearLayout {

private MapLocationOverlay overlay;

// Known lat/long coordinates that we'll be using.
private List mapLocations;

public static MapView mapView;

public LocationViewers(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public LocationViewers(Context context) {
super(context);
init();
}

public void init() {

setOrientation(VERTICAL);
setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));
String api = getResources().getString(R.string.map_api_key);
mapView = new MapView(getContext(),api);
mapView.setEnabled(true);
mapView.setClickable(true);
addView(mapView);
overlay = new MapLocationOverlay(this);
mapView.getOverlays().add(overlay);
mapView.getController().setZoom(5);
mapView.getController().setCenter(getMapLocations().get(0).getPoint());
}


public List getMapLocations() {
if (mapLocations == null) {
mapLocations = new ArrayList();
mapLocations.add(new MapLocation("Avinashi road, Coimbatore",11.0138,76.9871));
mapLocations.add(new MapLocation("Marina Beach, Chennai",13.0548,80.2830));
mapLocations.add(new MapLocation("Taj Mahal, New Delhi",28.6353,77.2250));
mapLocations.add(new MapLocation("Meenakshi Temple, Madurai",9.9195,78.1208));
}
return mapLocations;
}

public MapView getMapView() {
return mapView;
}
}



In this LocationViewers.java only we are using the MapView, then this file will be called in the map.xml


map.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_container" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.icons.draw.view.LocationViewers
android:id="@+id/map_location_viewer" android:layout_width="fill_parent"
android:layout_height="fill_parent" >


</com.icons.draw.view.LocationViewers>

<ZoomControls android:id="@+id/zoomcontrols"
android:gravity="bottom"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</FrameLayout>


In the above mentioned xml file we had used the ZoomControls also, this will be given the zoom listener on the java file


DrawIcons.java

package com.icons.draw;

import com.google.android.maps.MapActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ZoomControls;
import com.icons.draw.view.LocationViewers;

public class DrawIcons extends MapActivity {
@Override
public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.map);


ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LocationViewers.mapView.getController().zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LocationViewers.mapView.getController().zoomOut();
}
});
}

/**
* Must let Google know that a route will not be displayed
*/
@Override
protected boolean isRouteDisplayed() {
return false;
}
}



While pressing the zoom controls plus or minus, this listener will be called and the zoom functionality will be occurs. Then we are going to see two files MapLocation.java and MapLocationOverlay.java, where in the MapLocationOverlay file we will be drawing the marker and the info window for each marker, you can get the code from the zip file below.

The main thing to run the application is adding the internet permission and google library in the AndroidManifest.xml file


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.icons.draw"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DrawIcons"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="4" />

</manifest>



The code is fulling checked so you can run the code after downloading it itself.

You can download the full source code


Download source


Have a good day.