Step 1 :- Download Key tool From http://keytool.sourceforge.net/update.
Step 2 :- Install Key tool in eclipse.
Step 3 :- Go to key tool open key store.
Step 4:- File name = C:\Users\hm\.android\debug.keystore and password = android then click on load button.
Step 5 :- SHA1 Fingerprint like this :- 36:80:F9:C8:77:35:40:B4:0D:A1:84:92:29:34:E3:0F:0F:84:70:49
Step 6 :- goto google api console :- https://code.google.com/apis/console
then go to service tab and on all service related mapv2.
Step 7 :- go to api access click to create new android key.
Step 8 :- Copy sha1 key and your package name and create key.
key like this :- AIzaSyBK-AioGI3-RSeNEPtxMoxO48N91toj83w
Step 9 :- Go to android sdk manager and check Google play services available or not and install it.
Step 10 :- Go to your android project and open androidmanifest.xml file.
Step 11 :- add main.xml file.
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
Step 12 :- add Google lib service project
File --> Import --> android project --> Android-sdk --> extras --> google_play_servics --> library.
Step 13 :- goto project right click and go properties android add project for library.
Step 14 :- go to java file main.java and add code like this.
package com.example.map;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
static final LatLng user1 = new LatLng(53.558, 9.927);
static final LatLng user2 = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker user11 = map.addMarker(new MarkerOptions().position(user1)
.title("user1"));
Marker user22 = map.addMarker(new MarkerOptions()
.position(user2)
.title("user2")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(user1, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
Step 15 :- Run the project.
Out Put:-
Step 2 :- Install Key tool in eclipse.
Step 3 :- Go to key tool open key store.
Step 4:- File name = C:\Users\hm\.android\debug.keystore and password = android then click on load button.
Step 5 :- SHA1 Fingerprint like this :- 36:80:F9:C8:77:35:40:B4:0D:A1:84:92:29:34:E3:0F:0F:84:70:49
Step 6 :- goto google api console :- https://code.google.com/apis/console
then go to service tab and on all service related mapv2.
Step 7 :- go to api access click to create new android key.
Step 8 :- Copy sha1 key and your package name and create key.
key like this :- AIzaSyBK-AioGI3-RSeNEPtxMoxO48N91toj83w
Step 9 :- Go to android sdk manager and check Google play services available or not and install it.
Step 10 :- Go to your android project and open androidmanifest.xml file.
Step 11 :- add main.xml file.
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
Step 12 :- add Google lib service project
File --> Import --> android project --> Android-sdk --> extras --> google_play_servics --> library.
Step 13 :- goto project right click and go properties android add project for library.
Step 14 :- go to java file main.java and add code like this.
package com.example.map;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
static final LatLng user1 = new LatLng(53.558, 9.927);
static final LatLng user2 = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker user11 = map.addMarker(new MarkerOptions().position(user1)
.title("user1"));
Marker user22 = map.addMarker(new MarkerOptions()
.position(user2)
.title("user2")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(user1, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
Step 15 :- Run the project.
Out Put:-
No comments:
Post a Comment