0

我有这段代码可以在 google maps for android 上按地址进行功能搜索。我在姜饼模拟器上运行它,它不起作用。但是当我在 Eclair 上尝试它时,它可以工作。我已将最小 SDK 设置为 3,并且项目构建目标为 android google API 级别 9。有人可以告诉我问题出在哪里吗?谢谢。

public class ReverseGeocoding extends MapActivity
{

    btnSearch.setOnClickListener(new OnClickListener()
    {
        public void onClick(View v) 
        {


    String addressInput = adress.getText().toString();
            try 
            {
                List<Address> foundAdresses = gc.getFromLocationName(addressInput, 5);

                //fail to find the address
                if (foundAdresses.size() == 0)
                {
                    Dialog locationError = new AlertDialog.Builder(
                            ReverseGeocoding.this).setIcon(0).setTitle(
                            "WARNING").setPositiveButton(R.string.OK, null)
                            .setMessage("no location found").create();
                            locationError.show();
                }
                //if get the address
                else 
                {
                    for (int i = 0; i < foundAdresses.size(); ++i) 
                    {
                        Address x = foundAdresses.get(i);
                        lat = x.getLatitude();
                        lon = x.getLongitude();
                    }                   
                    navigateToLocation((lat * 1E6), (lon * 1E6), lat, lon, myMap);
                }
            }
            catch (Exception e)
            {
            }
        }
    });
}

//marking location
protected void navigateToLocation(double latitude, double longitude, final double lat2, final double lon2, MapView myMap)
{
    GeoPoint p = new GeoPoint((int) latitude, (int) longitude);

    Drawable icon = getResources().getDrawable(R.drawable.marker);
    icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon
            .getIntrinsicHeight());

    MyItemizedOverlay overlay = new MyItemizedOverlay(icon);
    OverlayItem item = new OverlayItem(p, "My Location", null);
    overlay.addItem(item);

    myMap.getOverlays().add(overlay);
    myMap.getController().animateTo(p);
    myMap.postInvalidate(); 

    myMap.displayZoomControls(true);
    myMap.getController().setZoom(15);
    myMap.setBuiltInZoomControls(true);

    MapController mc = myMap.getController();
    mc.animateTo(p);
    int zoomlevel = myMap.getMaxZoomLevel();
    mc.setZoom(zoomlevel - 1);
    myMap.setSatellite(false);  

    });
}

private GeoPoint getPoint(double lat, double lon) 
{
    return(new GeoPoint((int)(lat*1E6),(int)(lon*1E6)));
}   

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

}

4

2 回答 2

0
uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"
Declare the permission in manifest first
于 2013-01-22T12:03:14.760 回答
0

当我们声明活动时,在应用程序中声明库。

"<" 使用库 android:name="com.google.android.maps" "/>"

注意从“<>”中删除引号。

于 2013-01-25T10:27:28.893 回答