0

我已经编写了要在 Android 模拟器中查看的 Google 地图。但是,除了带有放大和缩小的网格之外,我什么也做不了。

这是我的清单代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ggl_maps"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="com.example.ggl_maps.MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="HelloItemizedOverlay" >
        </activity>
    </application>

</manifest> 

Java代码:

import java.util.List;

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.Overlay;
import com.google.android.maps.OverlayItem;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends MapActivity {

  MapView mapView;
  MapController mc;
  GeoPoint p;

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
      setContentView(R.layout.activity_main);
      mapView = (MapView) findViewById(R.id.mapView);
      mapView.setBuiltInZoomControls(true);
      mapView.setBuiltInZoomControls(true);

      List<Overlay> mapOverlays = mapView.getOverlays();
      Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
      HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);

      GeoPoint point2 = new GeoPoint(17385812, 78480667);
      OverlayItem overlayitem = new OverlayItem(point2, "Namashkaar!",
          "I'm in Hyderabad, India!");

      itemizedoverlay.addOverlay(overlayitem);
      mapOverlays.add(itemizedoverlay);

      List<Overlay> mapOverlay = mapView.getOverlays();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      Toast.makeText(getApplicationContext(), e.toString(), 5000).show();
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

  @Override
  protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
  }
}

覆盖.java

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;

    public HelloItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int arg0) {
        // TODO Auto-generated method stub
        return mOverlays.get(arg0);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return mOverlays.size();
    }
    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
    }

    @Override
    protected boolean onTap(int index) {
        OverlayItem item = mOverlays.get(index);
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
        return true;
    }
}

我的日志猫不断地运行并发出相同的警告。

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="AIzaSyB3XULMdQSsa**************************"
/>
</LinearLayout>

这是半日志猫的详细信息。同样继续运行几分钟。

    02-25 07:37:48.441: D/dalvikvm(650): GC_CONCURRENT freed 418K, 6% free 8563K/9095K, paused 10ms+5ms, total 86ms
02-25 07:38:12.761: E/ThrottleService(562): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
02-25 07:40:17.871: W/System.err(1249): IOException processing: 26
02-25 07:40:17.871: W/System.err(1249): java.io.IOException: Server returned: 3
02-25 07:40:17.891: W/System.err(1249):     at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
02-25 07:40:17.891: W/System.err(1249):     at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
02-25 07:40:17.945: W/System.err(1249):     at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
02-25 07:40:17.945: W/System.err(1249):     at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
02-25 07:40:17.945: W/System.err(1249):     at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
02-25 07:40:17.945: W/System.err(1249):     at java.lang.Thread.run(Thread.java:856)
4

1 回答 1

0
// Please check this runnig code..

public class MapViewActivity extends MapActivity  {

    private MapView mapView;
    private MapController mapController;
    private List<Overlay> mapOverlays;
    private MapOverlay itemizedOverlay;
    private GeoPoint geoPoint;
    private static double latitude;
    private static double longitude;
    private Button flashLightButton;
    private ImageView cloudImageView, networkImageView;
    private Context mContext;
    private Intent intent;

    protected void onCreate(Bundle icicle) {
        // TODO Auto-generated method stub
        super.onCreate(icicle);
        mContext = this;
        setContentView(R.layout.activity_app_map);

        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);
        mapController = mapView.getController();
        mapController.setZoom(13);
        try {
            LocationListenerClass.getInstance(this).getCurrentLocation();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (!GetPanelStatusEntityBean.getInstance().getLongitude().equals("")
                    && GetPanelStatusEntityBean.getInstance().getLongitude() != null) {
                longitude = Double.parseDouble(GetPanelStatusEntityBean
                    .getInstance().getCurrentLongitude());
                Log.v(ConstantLib.LOG, "PANEL LONGITUDE"
                    + GetPanelStatusEntityBean.getInstance()
                        .getCurrentLongitude());
            } else {
                longitude = Data.LONGITUDE;
            }
            if (!GetPanelStatusEntityBean.getInstance().getLatitude().equals("")
                    && GetPanelStatusEntityBean.getInstance().getLatitude() != null) {
                latitude = Double.parseDouble(GetPanelStatusEntityBean
                    .getInstance().getCurrentLatitude());
                Log.v(ConstantLib.LOG, "PANEL LATITUDE"
                    + GetPanelStatusEntityBean.getInstance()
                        .getCurrentLatitude());
            } else {
                latitude = Data.LATITUDE;
            }
        } catch (Exception e) {

        }

        geoPoint = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
        mapController.animateTo(geoPoint);

        mapView.invalidate();
        mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.pin);

        itemizedOverlay = new MapOverlay(drawable, this);
        OverlayItem overlayItem = new OverlayItem(geoPoint, null, null);

        itemizedOverlay.addOverlay(overlayItem);

        mapOverlays.add(itemizedOverlay);
    }

    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}
于 2013-02-25T07:02:59.860 回答