包com.google.android.maps不能得到解决 [英] Package com.google.android.maps cannot be resolved

查看:176
本文介绍了包com.google.android.maps不能得到解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要导入这些包
进口com.google.android.maps.MapActivity;
 进口com.google.android.maps.MapController;
 进口com.google.android.maps.MapView;

在我mainactivity.java

I want to import these packages import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; in my mainactivity.java

但是Eclipse无法解决这些包,我不知道这样做的原因。

But Eclipse cannot resolve these packages , and i don't know the reason for this.

我已经照着所有我上一本电子书中,一步一步的指示,就如何导入地图在你的应用程序,并且有这个错误只字不提。

I've followed all the instructions i found on an e-book , step by step,on how to import maps in your app, and there is nothing mentioned about this error.

下面是我的文件:

/////////// MainActivity.java /////////////////////

/////////// MainActivity.java /////////////////////

package com.paad.whereami;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends MapActivity {

//static final private int MENU_REFRESH = Menu.FIRST;

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

private LocationManager locationManager;
private String provider;
private Location location;

private final LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
        updateWithNewLocation(location);
    }
    public void onProviderDisabled(String provider){
        updateWithNewLocation(null);
    }
    public void onProviderEnabled(String provider){ }
    public void onStatusChanged(String provider, int status, Bundle extras){ }
};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_layout);
        mapView = (MapView)findViewById(R.id.map_view);

        locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        provider = locationManager.getBestProvider(criteria, true);
        location = locationManager.getLastKnownLocation(provider);

    //Log.v("BEFORE", "Location is: " + location);
    updateWithNewLocation(location);
    //Log.v("AFTER", "LOCATION FOUND");
    locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);
    }

    private void updateWithNewLocation(Location location){
        String latLongString;
        TextView myLocationText;
        myLocationText = (TextView)findViewById(R.id.myLocationText);

        String addressString = "No address found";

        if (location != null) {
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        latLongString = "Lat:" + lat + "\nLong:" + lng;

        //double latitude = 73.147536;
        //double longitude = 0.510638;
        Geocoder gc = new Geocoder(this, Locale.getDefault());

        try {
            List<Address> addresses = gc.getFromLocation(lat, lng, 1);
            Log.v("TRY_BODY", "All addresses are: " + addresses);
            StringBuilder sb = new StringBuilder();
            if (addresses.size() > 0) {
                Log.v("IF_BODY", "All addresses are: " + addresses);
                Address address = addresses.get(0);
                for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
                    sb.append(address.getAddressLine(i)).append("\n");
                    sb.append(address.getLocality()).append("\n");
                    sb.append(address.getPostalCode()).append("\n");
                    sb.append(address.getCountryName());
                }
                addressString = sb.toString();
            }
        } catch (IOException e) {}
        } 
        else {
        latLongString = "No location found";
        }

        myLocationText.setText("Current Pos:\n"+latLongString+"\n"+addressString);
    }

}

//////////// main.xml中/////////////////

//////////// main.xml /////////////////

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView  
    android:id="@+id/myLocationText"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
  />

  <com.google.android.maps.MapView
android:id="@+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="@string/myMapKey"
/>

</LinearLayout>

//////////////的Manifest.xml ////////////////

////////////// Manifest.xml ////////////////

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

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="15" />

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

        <application
            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=".MainActivity"
                android:label="@string/title_activity_main" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

</manifest>

先谢谢了。

推荐答案

在您的项目中右击--->属性 - > Android的 - >选择目标名称谷歌的API。和清洁工程和建设项目。

Right click on your projects ---> properties ---> android --> select target name Google ApIs. And Clean projects and Build the projects.

这篇关于包com.google.android.maps不能得到解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆