Wenn ich hier dem intent_addresse zb. "bernd" + "vogel 2" übergeb. Gibts einen FC .
1package com.restaurant;
2
3import java.io.IOException;
4import java.util.List;
5import java.util.Locale;
6
7import android.content.Intent;
8import android.graphics.Bitmap;
9import android.graphics.BitmapFactory;
10import android.graphics.Canvas;
11import android.graphics.Point;
12import android.location.Address;
13import android.location.Geocoder;
14import android.location.Location;
15import android.location.LocationManager;
16import android.net.Uri;
17import android.os.Bundle;
18import android.provider.Settings;
19import android.view.View;
20import android.view.View.OnClickListener;
21import android.widget.ImageButton;
22import android.widget.Toast;
23
24import com.google.android.maps.GeoPoint;
25import com.google.android.maps.MapActivity;
26import com.google.android.maps.MapController;
27import com.google.android.maps.MapView;
28import com.google.android.maps.MyLocationOverlay;
29import com.google.android.maps.Overlay;
30
31public class MyMapView extends MapActivity {
32
33 private MapView mMapView;
34 private MapController mMapController;
35 private LocationManager mLocationManager;
36 private Geocoder mGeocoder;
37 private String intent_addresse;
38 private MyLocationOverlay mOverlay;
39 private ImageButton img_bt_navigation;
40 private ImageButton img_bt_close;
41 private ImageButton img_bt_own;
42 private GeoPoint destination;
43
44 @Override
45 protected void onCreate(Bundle icicle) {
46 super.onCreate(icicle);
47 setContentView(R.layout.mymapview);
48
49 initButtons(); // Initialisiere Buttons
50 initMapView(); // Initialisiere MapView
51
52 intent_addresse = getIntent().getStringExtra("adresse"); // intent von
53
54 mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
55
56 setGPSon();
57
58 mGeocoder = new Geocoder(this, Locale.getDefault());
59
60 try {
61 List<Address> addresses = mGeocoder.getFromLocationName(
62 intent_addresse, 5);
63 if (addresses.size() > 0) {
64 destination = new GeoPoint((int) (addresses.get(0)
65 .getLatitude() * 1E6), (int) (addresses.get(0)
66 .getLongitude() * 1E6));
67
68 mMapController.animateTo(destination);
69 mMapView.invalidate();
70 }
71 } catch (IOException e) {
72 e.printStackTrace();
73 }
74
75 MapOverlay myMapOverlay = new MapOverlay();
76 List<Overlay> listOfOverlays = mMapView.getOverlays();
77 listOfOverlays.clear();
78 listOfOverlays.add(myMapOverlay);
79 }
80
81 private void initButtons() {
82 img_bt_navigation = (ImageButton) findViewById(R.id.img_bt_navigation);
83 img_bt_navigation.setOnClickListener(listener);
84
85 img_bt_own = (ImageButton) findViewById(R.id.img_bt_own);
86 img_bt_own.setOnClickListener(listener);
87
88 img_bt_close = (ImageButton) findViewById(R.id.img_bt_close);
89 img_bt_close.setOnClickListener(listener);
90 }
91
92 private OnClickListener listener = new OnClickListener() {
93 public void onClick(View v) {
94 switch (v.getId()) {
95 case R.id.img_bt_navigation:
96 String uri_navigation = "google.navigation:q="
97 + intent_addresse;
98 Intent intent_navigation = new Intent(Intent.ACTION_VIEW,
99 Uri.parse(uri_navigation));
100 startActivity(intent_navigation);
101 break;
102
103 case R.id.img_bt_own:
104 mMapController.animateTo(mOverlay.getMyLocation());
105 break;
106 case R.id.img_bt_close:
107 finish();
108 break;
109 }
110 }
111 };
112
113 @Override
114 protected void onPause() {
115 mOverlay.disableMyLocation();
116 mMapView.getOverlays().remove(mOverlay);
117 mLocationManager.removeUpdates(mOverlay);
118 super.onPause();
119 }
120
121 @Override
122 protected void onResume() {
123 super.onResume();
124
125 setGPSon();
126
127 mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
128 5000L, 500.0f, mOverlay);
129
130 mMapView.getOverlays().add(mOverlay);
131 mOverlay.enableMyLocation();
132
133 mOverlay.runOnFirstFix(new Runnable() {
134
135 public void run() {
136 mOverlay.getMyLocation();
137 }
138 });
139 }
140
141 private void setGPSon() {
142 if (!mLocationManager
143 .isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
144
145 Toast.makeText(this, "GPS ist deaktiviert, Bitte aktivieren !",
146 Toast.LENGTH_LONG).show();
147 Intent myIntent = new Intent(
148 Settings.ACTION_LOCATION_SOURCE_SETTINGS);
149 startActivity(myIntent);
150 }
151 }
152
153 private void initMapView() {
154 mMapView = (MapView) findViewById(R.id.mapview);
155 mOverlay = new MyLocationOverlay(this, mMapView) {
156
157 @Override
158 public synchronized void onLocationChanged(Location location) {
159 super.onLocationChanged(location);
160 }
161 };
162 mMapController = mMapView.getController();
163
164 final int maxZoomlevel = mMapView.getMaxZoomLevel();
165 mMapController.setZoom(maxZoomlevel - 2);
166 // mMapView.setBuiltInZoomControls(true);
167 }
168
169 @Override
170 protected boolean isRouteDisplayed() {
171 return false;
172 }
173
174 class MapOverlay extends com.google.android.maps.Overlay {
175 @Override
176 public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
177 long when) {
178 super.draw(canvas, mapView, shadow);
179
180 Point screenPts = new Point();
181 mapView.getProjection().toPixels(destination, screenPts);
182
183 Bitmap bmp = BitmapFactory.decodeResource(getResources(),
184 R.drawable.restaurant_icon);
185 canvas.drawBitmap(bmp, screenPts.x - 34, screenPts.y - 34, null);
186 return true;
187 }
188 }
189}
— geändert am 24.01.2012, 22:29:34
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.