2012-11-25 92 views
0

我有問題,在谷歌地圖的Android搜索spesific位置

這裏的搜索位置是我的cari.java

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


import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 
import com.google.android.maps.Overlay; 


import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.Intent; 
import android.location.Address; 
import android.location.Geocoder; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.TextView; 

public class cari extends com.google.android.maps.MapActivity { 

     TextView error,pt; 
     EditText cm; 
     String i,returnStringLancar,stat; 
     Geocoder geoCoder; 
     GeoPoint p; 
     MapController controller; 
     MapView map; 
     /** Called when the activity is first created. */ 

     @Override 


     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.search); 

      pt=(TextView)findViewById(R.id.peta); 
      cm=(EditText)findViewById(R.id.cariMap); 




     } 

     public void clickHandler(View view){ 
      Intent a = null; 
      switch (view.getId()){ 
      case R.id.show: 
       geoCoder = new Geocoder(getApplicationContext(), 
         Locale.getDefault()); 
       List<Address> addresses; 
       try { 
        addresses = geoCoder.getFromLocationName(cm.getText().toString(),5); 
       if(addresses.size() > 0) 
       { 
        p = new GeoPoint((int) (addresses.get(0).getLatitude() * 1E6), 
             (int) (addresses.get(0).getLongitude() * 1E6)); 

         controller.animateTo(p); 
         controller.setZoom(12); 

         MapOverlay mapOverlay = new MapOverlay(); 
        List<Overlay> listOfOverlays = map.getOverlays(); 
        listOfOverlays.clear(); 
        listOfOverlays.add(mapOverlay); 

         map.invalidate(); 
         cm.setText(""); 
       } 
       else 
       { 
         AlertDialog.Builder adb = new AlertDialog.Builder(cari.this); 
         adb.setTitle("Google Map"); 
         adb.setMessage("Please Provide the Proper Place"); 
         adb.setPositiveButton("Close",null); 
         adb.show(); 
       } 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
       break; 
     } 
     } 

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

代碼,這是我MapOverlay.java

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapView; 

import android.app.Activity; 
import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.Canvas; 
import android.graphics.Point; 
import android.os.Bundle; 

class MapOverlay extends com.google.android.maps.Overlay 
{ 
    Context context; 
    GeoPoint p; 
    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(
      context.getResources(), R.drawable.icon);    
     canvas.drawBitmap(bmp, screenPts.x, screenPts.y-32, null);   
     return true; 
    } 
} 

該程序的目的是通過地址(例如:第五大道)搜索谷歌地圖的位置。

但是當我部署此,它顯示出這樣的錯誤:

了java.lang.RuntimeException:無法實例活動ComponentInfo {udin.googlemap2/udin.googlemap2.GoogleMap2}:

和這樣的:

loader中的java.lang.ClassNotFoundException:udin.googlemap2.GoogleMap2 dalvik.system.PathClassLoader [/system/framework/com.google.android.maps.jar:/data/app/udin.googlemap2-1.apk ]

你能幫我嗎?已經還剩1天完成我的計劃

我會很高興,並感謝您的幫助

感謝反正

+0

http://stackoverflow.com/q/13552344/1782481請不要轉發您的問題,只需改進之前的版本即可。如果你一遍又一遍地發佈相同的問題,這不會給你更多的幫助。 – varevarao

回答

1

檢查是否<uses-library android:name="com.google.android.maps" />在android系統manifest..It給出都會好起來的。