2013-12-24 124 views
0

我想構建一個簡單的應用程序,當用戶輸入他想要的位置時,它的地圖會顯示。但我收到錯誤無法實例化類型GeoPoint我也安裝了Google Play服務。 這裏是代碼:無法實例化類型GeoPoint Android

public class MainActivity extends MapActivity { 

EditText location; 
Geocoder geoCoder; 
GeoPoint p; 
MapController controller; 
MapView mapView; 
Button btnSearch; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    location=(EditText)findViewById(R.id.txtAddress); 
    mapView = (MapView) findViewById(R.id.mapView); 
    btnSearch.setOnClickListener(new View.OnClickListener() {        

     public void onClick(View arg0) { 


    List<Address> addresses; 
    try { 
     addresses = geoCoder.getFromLocationName(location.getText().toString(),1); 
     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 = mapView.getOverlays(); 
        listOfOverlays.clear(); 
      listOfOverlays.add(mapOverlay); 

       mapView.invalidate(); 
       location.setText(""); 
     } 
     else 
     { 
       AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.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(); 
    } 
     } 
     }); 



} 
+0

你有'import com.google.android.maps.GeoPoint;' – Raghunandan

+0

你可以顯示你的錯誤嗎? – GrIsHu

+0

導入該庫,但無法啓動我的app.null啓動取消異常,我已經嘗試了許多選項,如擦除用戶數據,自動 選擇目標並重置abd.but沒有工作 – Wasfa

回答

0

是否有你需要的V1谷歌地圖API的使用特定的原因,而不是當前V2?如果沒有,請嘗試使用LatLng存儲位置,然後使用map.moveCamera(LatLng,float zoom)轉到所需位置,如here所示。