Here you can find how to use Google Maps in your Android applications and how to programmatically perform the following:
- Change the views of Google Maps
- Obtain the latitude and longitude of locations in Google Maps
- Perform geocoding and reverse geocoding
- Add markers to Google Maps
1)Create New android Application.
File->NewAndroid Application
2) Get Google map API key as described in previous post.3) To use Google maps in your application your internet permission should be enable in your androidManifest.xml file and you have to use com.google.android.maps library.
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
4) To display Map Modify your main.xml file located at res/layout. You have to use the <com.google.android.maps.MapView> element to display the Google Maps in your activity.
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0sNknjkiYKLIEZc3LBzrXpmdxnkyTFDQcjhRpRQ"
/>
you have to replace androdi:apiKey value with your Google Map API key from post.
5) Now edit your .java file, to get map have to inherit your class with MapActivity class instead of Activity, IsRuteDisplayed() is Override method. your .java file should be like this.
package com.map;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class HelloGoogleMaps extends MapActivity {
private MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
Now run the application to view the output.
No comments:
Post a Comment