Rutas Del Estilo PDF
Rutas Del Estilo PDF
626841,17z
can
locate
play
services
library
project
from
android-sdk-windows\extras\google\google_play_services\libproject\google-playservices_lib
3. Importantly while importing check Copy projects into workspace option as shown in
the below image.
On Linux or Mac OS
4. Now select API Access on left side and on the right side click on Create new Android
key
5. It will popup a window asking the SHA1 and package name. Enter your S HA 1 and
your and roi d p roj ec t pa c ka ge name separated by semicolon ; and click on create.
BE:03:E1:44:39:7B:E8:17:02:9F:7F:B7:98:82:EA:DF:84:D0:FB:6A;info.androidhive.googlema
And note down the API key which required later in our project.
3. Add the Map Key in the manifest file. Open A nd roi dMan if es t.x ml file and add the
following code before tag. Replace the and roi d:va lu e with your map key which you got
from google console.
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBZMlkOv4sj-M5JO9p6wksdax4TEjDVLgo" />
or
INTE RN ET
To
check
not
internet
connection
status
map
data
in
external
storage
cell
AC CE SS_ FI NE_LO CA TI ON
To
data
determine
users
location
using
GPS
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEI
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GS
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="info.androidhive.googlemapsv2.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
android:value="AIzaSyBZMlkOv4sj-M5JO9p6wksdax4TEjDVLgo" />
</application>
</manifest>
5. New google maps are implemented using MapF ragm en ts which is a sub class
of Fr agme nt s class. Open your main activity layout file ac ti vi ty_ma in.x ml file and
add following code. I usedRe lat iv eLayou t as a parent element. You can remove it and
use MapFragment directly.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android "
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
6. Add the following code in your Main Activity java (Mai nA ct iv ity .java ) class.
MainActivity.java
public class MainActivity extends Activity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
Run your project and congratulations if you see a map displaying on your device.
Placing a Marker
You can place a marker on the map by using following code.
// latitude and longitude
double latitude = ;
double longitude = ;
// create marker
// adding marker
googleMap.addMarker(marker);
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
Apart from maps native marker icons, you can use own image to show as a marker. You can
load the icon from any kind of supported sources.
fr om Ass et (S tr in g
fr omB it map
fr om Fi le
ass et Na me )
( Bi tm ap
( St ri ng
Loading
from
assets
folder
imag e)
Loading
bitmap
image
pat h)
Loading
from
file
// create marker
// adding marker
googleMap.addMarker(marker);
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Following are enhancements and features that google maps provides. You can utilize these
features which suites to your requirements.
can
show
users
current
location
on
the
map
by
calling se tMyLo cat ion Enab le d( ) . Pass true / false to enable or disable this feature
googleMap.setMyLocationEnabled(true); // false to disable
Zooming Buttons
You can call se tZoom Con tr ol sEna ble d( ) function to get rid of those zooming
controls on the map. By disabling these buttons map zooming functionality still work by
pinching gesture.
googleMap.getUiSettings().setZoomControlsEnabled(false); // true to enable
Zooming Functionality
You
can
disable
zooming
gesture
functionality
Compass Functionality
Compass can be disabled by calling se tC ompa ssEna bl ed () function
googleMap.getUiSettings().setCompassEnabled(true);
My Location Button
by
My location button will be used to move map to your current location. This button can be
shown / hidden by calling se tMyLo cat ion Bu tt onE nab le d( ) function
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
rotate
gesture
can
be
enabled
or
disabled
by
Although google maps provides lot of other features, I covered only basic topics in this
tutorial. Remaining topics seems to be pretty much lengthy, so Ill post them as separate
articles.
Share this article on
http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/