0

我对 googlemap 应用程序有一个小问题,我想使用本教程来处理我的 Eclipse,我已经更新了所有 Elipse ADT,下载了 GoogleAPI,但我仍然从我的 HelloWorld 应用程序所在的 MapActivity 的 IDE 中收到错误被扩展不能解析为一个类型。我是否遗漏了一些重要的导入或设置,我需要在 Eclipse 本身上执行以使其工作?

public class HelloGoogleMapActivity extends MapActivity {
    /** Called when the activity is first created. */
    @override
    protected boolean isRoundDisplayed()
    {
        return false;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MapView mapv=(MapView)findViewById(R.id.mapview);
        mapv.setBuildInZoomControls(true);
    }
}

第一个“@override”关键字也被报告为非法,我不知道为什么。

[更新]

提供的所有答案都是正确的。最正确的是下面的评论。感谢您的代码剪辑。凉爽的!

4

3 回答 3

1

对于 @Override 异常 jst 一旦 javacompiler 从您的项目属性中更改 ...JDK 合规性 1.6 到 1.5 然后再次将其设置为 1.6 ...我面临同样的问题 .. 它是一些 jdk 构建项目的 bcz .​​..或日食问题...

对于地图 Prob

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.google.android.maps.MapView
        android:id="@+id/showmap"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:apiKey="@string/mapkey"
        android:clickable="true" />

</RelativeLayout>

活动.java

MapView mapView;

@Override
    protected void onCreate(Bundle icicle) {

        try {
            super.onCreate(icicle);
            setContentView(R.layout.map_screen);
            mapView = (MapView) findViewById(R.id.showmap);
            mapView.setBuiltInZoomControls(true);
            final MapController mc = mapView.getController();
            mc.animateTo(new GeoPoint(((int) (latitude * 1E6) - 10),
                    ((int) (longitude * 1E6)) - 10));
            mc.setZoom(5);
        } catch (Exception e) {
            Log.e("MapCreate", e.getMessage());
        }

应用程序清单.xml

    <uses-permission android:name="android.permission.INTERNET" />
        <application
                android:icon="@drawable/ic_launcher"
                android:label="Andro Integration"
                android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >


                <uses-library android:name="com.google.android.maps" />
    <!--         <activity -->

<!--         </activity> -->

        </application>
于 2012-04-17T06:39:05.110 回答
1

爪哇

package com.manit.HelloGoogleMaps2;

import java.util.List;        
import android.graphics.drawable.Drawable;    
import android.os.Bundle;   
import com.google.android.maps.GeoPoint;    
import com.google.android.maps.MapActivity;    
import com.google.android.maps.MapView;    
import com.google.android.maps.Overlay;    
import com.google.android.maps.OverlayItem;    

public class HelloGoogleMaps2 extends MapActivity {    
/** Called when the activity is first created. */    
@Override    
public void onCreate(Bundle savedInstanceState) {    
    super.onCreate(savedInstanceState);    
    setContentView(R.layout.main);    

    MapView mapView = (MapView) findViewById(R.id.mapview);    
    mapView.setBuiltInZoomControls(true);

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
    GeoPoint point = new GeoPoint(30443769,-91158458);
    OverlayItem overlayitem = new OverlayItem(point, "hi", "I'm in India!");

    GeoPoint point2 = new GeoPoint(17385812,78480667);
    OverlayItem overlayitem2 = new OverlayItem(point2, "hi!", "I'm in Ahmedabad, India!");

    itemizedoverlay.addOverlay(overlayitem);
    itemizedoverlay.addOverlay(overlayitem2);

    mapOverlays.add(itemizedoverlay);
}

@Override
protected boolean isRouteDisplayed()
{
return false;
}   }       

HelloItemizedOverlay.java

package com.manit.HelloGoogleMaps2;

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<OverlayItem>{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
 private Context mContext;

public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
    // TODO Auto-generated constructor stub
    super(boundCenterBottom(defaultMarker));
     mContext = context;
}

public void addOverlay(OverlayItem overlay)
 {
 mOverlays.add(overlay);
 populate();
 }
 @Override
 protected OverlayItem createItem(int i)
 {
 return mOverlays.get(i);
 }
 @Override
 public int size()
 {
 return mOverlays.size();
 }
 @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;
 }

}

Androidmanifest.xml

    <?xml version="1.0" encoding="utf-8"?>
            <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                  package="com.manit.HelloGoogleMaps2"
                  android:versionCode="1"
                  android:versionName="1.0">
                <uses-sdk android:minSdkVersion="7" />

                <application android:icon="@drawable/icon" android:label="@string/app_name">
                    <activity android:name=".HelloGoogleMaps2"
                              android:label="@string/app_name">
                        <intent-filter>
                            <action android:name="android.intent.action.MAIN" />
                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                    </activity>
            <uses-library android:name="com.google.android.maps" />
                </application>
                <uses-permission android:name="android.permission.INTERNET" />
            </manifest>

主要的.xml

<?xml version="1.0" encoding="utf-8"?>
    <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="0Y2GRNdvsKsNO5cbkNKYcht3_0ASApwak-Q19Fg"
    />

字符串.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloGoogleMaps!</string>
<string name="app_name">Hello,GoogleMaps</string>
<string name="mapskey">0Y2GRNdvsKsNO5cbkNKYcht3_0ASApwak-Q19Fg</string>
</resources>
于 2012-04-17T06:39:26.037 回答
0

使用以下代码供您使用....当我尝试显示地图时,此代码工作正常...
代码中所需的 更改

public class GoogleMapsActivity extends MapActivity implements LocationListener{
/** Called when the activity is first created. */
MapView mapView; 
MapController mc;
GeoPoint p;
String add = "";
double lattitude ;
double longitude;
String selectedprofile;
AudioManager am;
Button search;
EditText placeSearch;


class MapOverlay extends com.google.android.maps.Overlay
{
    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);                   

        //---translate the GeoPoint to screen pixels---
        Point screenPts = new Point();
        mapView.getProjection().toPixels(p, screenPts);

        //---add the marker---
        Bitmap bmp = BitmapFactory.decodeResource(
            getResources(), R.drawable.pushpin2);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        add="";
        //---when user lifts his finger---
        if (event.getAction() == 1) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());


            Geocoder geoCoder = new Geocoder(
                    getBaseContext(), Locale.getDefault());
                try {
                    List<Address> addresses = geoCoder.getFromLocation(
                        p.getLatitudeE6()  / 1E6, 
                        p.getLongitudeE6() / 1E6, 1);

                    lattitude=p.getLatitudeE6()  / 1E6;
                    longitude=p.getLongitudeE6() / 1E6;

                    if (addresses.size() > 0) 
                    {
                        for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); 
                             i++)
                           add += addresses.get(0).getAddressLine(i) + "\n";
                    }

                    Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();


                }
                catch (IOException e) {                
                    e.printStackTrace();
                }   
                return true;

        }                
        else {
        return false;
        }
    }        
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent=getIntent();
    setResult(RESULT_OK, intent);



    mapView = (MapView) findViewById(R.id.mapView);
    LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
    View zoomView = mapView.getZoomControls(); 

    zoomLayout.addView(zoomView, 
        new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, 
            LayoutParams.WRAP_CONTENT)); 
    mapView.displayZoomControls(true);

    mc = mapView.getController();
    String coordinates[] = {"1.352566007", "103.78921587"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    p = new GeoPoint(
        (int) (lat * 1E6), 
        (int) (lng * 1E6));

    mc.setCenter(p);
    mc.setZoom(17); 

    //---Add a location marker---
    MapOverlay mapOverlay = new MapOverlay();
    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);      

    //mapView.invalidate();
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this);
}
于 2012-04-17T06:19:20.370 回答