name=".widget.MovieSearchWidget$UpdateService"/>
...
[代码]LbsGeocodingActivity.java
packagecom.javacodegeeks.android.lbs;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.location.Location;
importandroid.location.LocationListener;
importandroid.location.LocationManager;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.Toast;
publicclassLbsGeocodingActivityextendsActivity{
privatestaticfinallongMINIMUM_DISTANCE_CHANGE_FOR_UPDATES=1;//inMeters
privatestaticfinallongMINIMUM_TIME_BETWEEN_UPDATES=1000;//inMilliseconds
protectedLocationManagerlocationManager;
protectedButtonretrieveLocationButton;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
retrieveLocationButton=(Button)findViewById(R.id.retrieve_location_button);
locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
newMyLocationListener()
);
retrieveLocationButton.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
showCurrentLocation();
}
});
}
protectedvoidshowCurrentLocation(){
Locationlocation=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location!
=null){
Stringmessage=String.format(
"CurrentLocation\nLongitude:
%1$s\nLatitude:
%2$s",
location.getLongitude(),location.getLatitude()
);
Toast.makeText(LbsGeocodingActivity.this,message,
Toast.LENGTH_LONG).show();
}
}
privateclassMyLocationListenerimplementsLocationListener{
publicvoidonLocationChanged(Locationlocation){
Stringmessage=String.format(
"NewLocation\nLongitude:
%1$s\nLatitude:
%2$s",
location.getLongitude(),location.getLatitude()
);
Toast.makeText(LbsGeocodingActivity.this,message,Toast.LENGTH_LONG).show();
}
publicvoidonStatusChanged(Strings,inti,Bundleb){
Toast.makeText(LbsGeocodingActivity.this,"Providerstatuschanged",
Toast.LENGTH_LONG).show();
}
publicvoidonProviderDisabled(Strings){
Toast.makeText(LbsGeocodingActivity.this,
"Providerdisabledbytheuser.GPSturnedoff",
Toast.LENGTH_LONG).show();
}
publicvoidonProviderEnabled(Strings){
Toast.makeText(LbsGeocodingActivity.this,
"Providerenabledbytheuser.GPSturnedon",
Toast.LENGTH_LONG).show();
}
}
}
[代码]GMapsActivity.java
packagecom.javacodegeeks.android.googlemaps;
importjava.util.List;
importandroid.graphics.drawable.Drawable;
importandroid.os.Bundle;
importcom.google.android.maps.GeoPoint;
importcom.google.android.maps.MapActivity;
importcom.google.android.maps.MapController;
importcom.google.android.maps.MapView;
importcom.google.android.maps.Overlay;
importcom.google.android.maps.OverlayItem;
publicclassGMapsActivityextendsMapActivity{
privateMapViewmapView;
privatestaticfinalintlatitudeE6=37985339;
privatestaticfinalintlongitudeE6=23716735;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView=(MapView)findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
ListmapOverlays=mapView.getOverlays();
Drawabledrawable=this.getResources().getDrawable(R.drawable.icon);
CustomItemizedOverlayitemizedOverlay=
newCustomItemizedOverlay(drawable,this);
GeoPointpoint=newGeoPoint(latitudeE6,longitudeE6);
OverlayItemoverlayitem=
newOverlayItem(point,"Hello","I'minAthens,Greece!
");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
MapControllermapController=mapView.getController();
mapController.animateTo(point);
mapController.setZoom(6);
}
@Override
protectedbooleanisRouteDisplayed(){
returnfalse;
}
}
[代码]CustomItemizedOverlay.java
packagecom.javacodegeeks.android.googlemaps;
importjava.util.ArrayList;
importandroid.app.AlertDialog;
importandroid.content.Context;
importandroid.graphics.drawable.Drawable;
importcom.google.android.maps.ItemizedOverlay;
importcom.google.android.maps.OverlayItem;
publicclassCustomItemizedOverlayextendsItemizedOverlay{
privateArrayListmapOverlays=newArrayList();
privateContextcontext;
publicCustomItemizedOverlay(DrawabledefaultMarker){
super(boundCenterBottom(defaultMarker));
}
publicCustomItemizedOverlay(DrawabledefaultMarker,Contextcontext){
this(defaultMarker);
this.context=context;
}
@Override
protectedOverlayItemcreateItem(inti){
returnmapOverlays.get(i);
}
@Override
publicintsize(){
returnmapOverlays.size();
}
@Override
protectedbooleanonTap(intindex){
OverlayItemitem=mapOverlays.get(index);
AlertDialog.Builderdialog=newAlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
returntrue;
}
publicvoidaddOverlay(OverlayItemoverlay){
mapOverlays.add(overlay);
this.populate();
}
}
[代码]layout.xml
xmlversion="1.0"encoding="utf-8"?
>
xmlns:
android="schemas.android/apk/res/android"
android:
orientation="vertical"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
xmlns:
android="schemas.android/apk/res/android"
android:
id="@+id/map_view"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
clickable="true"
android:
enabled="true"
android:
apiKey="API-KEY-HERE"/>
[代码]AndroidManifest.xml
xmlversion="1.0"encoding="utf-8"?
>
android="schemas.android/apk/res/android"
package="com.javacodegeeks.android.googlemaps"
android:
versionCode="1"
android:
versionName="1.0">
icon="@drawable/icon"android:
label="@string/app_name">
name=".GMapsActivity"
android:
label="@string/app_name">
name="android.intent.action.MAIN"/>
name="android.intent.category.LAUNCHER"/>
name="com.google.android.maps"/>
name="android.permission.INTERNET"/>
[代码][Java]代码
privatevoidstartAnimationPopOut(){
LinearLayoutmyLayout=(LinearLayout)findViewById(R.id.anim_layout);
Animationanimation=AnimationUtils.loadAnimation(this,R.anim.bottom_out);
animation.setAnimationListener(newAnimationListener(){
@Override
publicvoidonAnimationStart(Animationanimation){
}
@Override
publicvoidonAnimationRepeat(Animationanimation){
}
@Override
publicvoidonAnimationEnd(Animationanimation){
}
});
myLayout.clearAnimation();
myLayout.startAnimation(animation);
}
[代码][XML]代码
xmlversion="1.0"encoding="utf-8"?
>
xmlns:
android="schemas.android/apk/res/android"
android:
interpolator="@android:
anim/accelerate_interpolator">
android:
fromYDelta="0%"
android:
toYDelta="60%"
android:
duration="700">