我开发了一个应用程序,我想在其中使用谷歌地图来显示位置视图,我从堆栈溢出和谷歌也发现了许多有用的概念,并通过遵循这些成功实现了我的应用程序。我的应用程序正在运行,没有任何错误但没有显示正确的地图。
我得到的输出:
这是我的 Java 文件:
package com.mapactivity;
import java.util.List;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.KeyEvent;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
public class MainActivity extends MapActivity implements LocationListener{
MapView mapView;
MapController mc;
GeoPoint gp;
MyLocationOverlay compass;
long start;
long stop;
Drawable d;
List<Overlay> overlayList;
LocationManager lm;
String towers;
/*int lat;
int longi;*/
int x,y;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mc = mapView.getController();
String cordinate[] = {"28.636041","77.223957"};
double lat = Double.parseDouble(cordinate[0]);
double lng = Double.parseDouble(cordinate[1]);
gp = new GeoPoint((int)(lat*1E6), (int)(lng*1E6));
mc.animateTo(gp);
mc.setZoom(13);
MapOverlay mo = new MapOverlay();
List<Overlay> list = mapView.getOverlays();
list.clear();
list.add(mo);
mapView.invalidate();
}
public boolean onKeyDown(int keyCode,KeyEvent event)
{
mc = mapView.getController();
switch (keyCode) {
case KeyEvent.KEYCODE_3:
mc.zoomIn();
break;
case KeyEvent.KEYCODE_1:
mc.zoomOut();
}
return super.onKeyDown(keyCode, event);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapview, boolean shadow, long when) {
// TODO Auto-generated method stub
super.draw(canvas, mapview, shadow);
Point screenPoint = new Point();
mapview.getProjection().toPixels(gp, screenPoint);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker_landmark);
canvas.drawBitmap(bmp, screenPoint.x, screenPoint.y-50,null);
return true;
}
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
而且我也在清单文件中授予了所有权限,但没有得到正确的东西,请让我知道我做错了什么。