2014-10-30 4 views
0

osmdroid 및 Mapnik을 사용합니다! 내 문제는 지오 픽스 명령을 사용할 때 위도와 경도가 화면에 표시되지만 위치가 아니라는 것을 알 수 있습니다. 내지도가 새 위치로 이동하지 않는다는 것을 의미합니다. 누군가 도와 줄 수 있어요. 10-29 10:31:43.649: I/dalvikvm(309): Could not find method android.animation.ValueAnimator.ofFloat, referenced from method org.osmdroid.views.MapController.<init> 여기 내 코드입니다 : 난 항상이 오류가 나는 메뉴 "마 위치"여기 (itme1) 을 누르면 내가 말했듯이오버레이 및 osmdroid

package com.formation.mine; 

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

import org.osmdroid.DefaultResourceProxyImpl; 
import org.osmdroid.ResourceProxy; 
import org.osmdroid.api.IMapView; 
import org.osmdroid.tileprovider.tilesource.TileSourceFactory; 
import org.osmdroid.util.GeoPoint; 
import org.osmdroid.util.ResourceProxyImpl; 
import org.osmdroid.views.MapView; 
import org.osmdroid.views.overlay.ItemizedOverlay; 
import org.osmdroid.views.overlay.OverlayItem; 

import android.app.Activity; 
import android.content.Context; 
import android.graphics.Point; 
import android.graphics.drawable.Drawable; 
import android.location.Address; 
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.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.widget.TextView; 
import android.widget.Toast; 


public class MainActivity extends Activity implements LocationListener { 


    LocationManager locationManager; 
    Geocoder geocoder;             //convertit les adresses en latitude et longitude 
    TextView locationText; 
    ResourceProxy mResourceProxy; 
    MapView m_mapview; 

    //Constantes 
    double LATITUDE = -12.276610; 
    double LONGITUDE = 49.292531;  //Grand Hotel 


    // Called when the activity is first created 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     GeoPoint point = new GeoPoint(microdegrees (LATITUDE) , microdegrees(LONGITUDE)); 
     mResourceProxy = new ResourceProxyImpl(getApplicationContext()); 
     MonOverlay object = new MonOverlay(getResources().getDrawable(R.drawable.marker), mResourceProxy); 
     locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE); 
     geocoder = new Geocoder(this); 

     locationText = (TextView)this.findViewById(R.id.lblLocationInfo); 
     m_mapview = (MapView) findViewById(R.id.mapview); 

     m_mapview.setBuiltInZoomControls(true); 
     m_mapview.setMultiTouchControls(true); 
     m_mapview.setUseDataConnection(true); 
     m_mapview.setBackgroundColor(BIND_AUTO_CREATE);        //encore à choisir une couleur 
     object.addPoint(point); 
     m_mapview.getOverlays().add(object); 
     m_mapview.getController().setZoom(15); 
     m_mapview.getController().setCenter(point); 
     m_mapview.setTileSource(TileSourceFactory.MAPNIK); 

    } 

      //Pour avoir les valeurs des latitudes et longitudes en degré 
      private int microdegrees(double value){ 
       return (int)(value*1000000); 
      } 

      //Classe et Méthodes d'Overlays 
      public class MonOverlay extends ItemizedOverlay<OverlayItem>{ 

        List<GeoPoint> points = new ArrayList<GeoPoint>(); 
        public MonOverlay(Drawable pDefaultMarker, 
          ResourceProxy pResourceProxy) { 
         super(pDefaultMarker, pResourceProxy); 
         // TODO Auto-generated constructor stub 
        } 
        @Override 
        public boolean onSnapToItem(int i, int arg1, Point arg2, 
          IMapView arg3) { 
         // TODO Auto-generated method stub 
         return false; 
        } 
        @Override 
        protected OverlayItem createItem(int i) { 
         GeoPoint point = points.get(i); 
         return new OverlayItem("Description","Titre",point);        
        } 
        @Override 
        public int size() { 
         return points.size(); 
        } 
        public void addPoint(GeoPoint point){ 
         this.points.add(point); 
         populate(); 
        }    
      } 

      //LES METHODES DU LOCATION-MANAGER 
      @Override 
      protected void onResume() { 
       super.onResume(); 
       locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, this); //<7> 
      } 

      @Override 
      protected void onPause() { 
       super.onPause(); 
       locationManager.removeUpdates(this); 
      } 

      @Override 
      public void onLocationChanged(Location location) { 
       String text = String.format("Latitude:\t %f\nLongitude:\t %f\nAltitude:\t %f\nBearing:\t %f", location.getLatitude(), 
         location.getLongitude(), location.getAltitude(), location.getBearing()); 

       Context context = getApplicationContext(); 
        int duration = Toast.LENGTH_LONG; 
        Toast toast = Toast.makeText(context,text, duration); 
        toast.show(); 


       try { 
        List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); 
        for (Address address : addresses) { 
         this.locationText.append("\n" + address.getAddressLine(0)); } 

        int latitude = (int)(location.getLatitude() * 1000000); 
        int longitude = (int)(location.getLongitude() * 1000000); 

        GeoPoint point = new GeoPoint(latitude,longitude); 
        mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext()); 
//     m_mapview.getController().animateTo(point); 

        MonOverlay object = new MonOverlay(getResources().getDrawable(R.drawable.marker), mResourceProxy); 
        object.addPoint(point); 
        m_mapview.getOverlays().add(object); 
        m_mapview.getController().setZoom(15); 
        m_mapview.getController().setCenter(point); 


       } catch (IOException e) { 
        Log.e("LocateMe", "Could not get Geocoder data", e); 
       } 


      } 
      @Override 
      public void onProviderDisabled(String arg0) { 
       // TODO Auto-generated method stub 
      } 
      @Override 
      public void onProviderEnabled(String arg0) { 
       // TODO Auto-generated method stub 
      } 
      @Override 
      public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
       // TODO Auto-generated method stub 
      } 


      //CREATION DES METHODES MENUS 
      @Override 
      public boolean onCreateOptionsMenu(Menu menu) { 
       // Inflate the menu; appel au menu.menu 
       MenuInflater inflater = getMenuInflater(); 
        inflater.inflate(R.menu.menu,menu);     //menu.ma_position 
        return true; 
      } 
      //Pour le choix des menus 
      @Override 
      public boolean onOptionsItemSelected(MenuItem item) { 
       // Handle item selection 
       switch (item.getItemId()) { 
        case R.id.item1: 
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
        if (location != null) { 
         this.onLocationChanged(location); 
         }else{ 
          Context context = getApplicationContext(); 
          int duration = Toast.LENGTH_SHORT; 
          Toast toast = Toast.makeText(context, "Vous êtes toujours sur la même position", duration); 
          toast.show(); 

         } 
         return true; 
//     case R.id.help: 
//      showHelp(); 
//      return true; 
        default: 
         return super.onOptionsItemSelected(item); 
       } 
      } 
}   

, 나는이 에러가 발생하는 몇 가지 오류입니다 :

10-30 14:54:55.181: I/dalvikvm(306): Could not find method android.animation.ValueAnimator.ofFloat, referenced from method org.osmdroid.views.MapController.<init> 
10-30 14:54:55.191: W/dalvikvm(306): VFY: unable to resolve static method 14: Landroid/animation/ValueAnimator;.ofFloat ([F)Landroid/animation/ValueAnimator; 
10-30 14:54:55.191: D/dalvikvm(306): VFY: replacing opcode 0x71 at 0x001a 
10-30 14:54:55.201: D/dalvikvm(306): VFY: dead code 0x001d-005d in Lorg/osmdroid/views/MapController;.<init> (Lorg/osmdroid/views/MapView;)V 
10-30 14:54:55.221: I/dalvikvm(306): Could not find method android.animation.Animator.end, referenced from method org.osmdroid.views.MapController.stopAnimation 
10-30 14:54:55.221: W/dalvikvm(306): VFY: unable to resolve virtual method 6: Landroid/animation/Animator;.end()V 
10-30 14:54:55.231: D/dalvikvm(306): VFY: replacing opcode 0x6e at 0x002e 
10-30 14:54:55.251: I/dalvikvm(306): Could not find method android.animation.ValueAnimator.start, referenced from method org.osmdroid.views.MapController.zoomInFixing 
10-30 14:54:55.251: W/dalvikvm(306): VFY: unable to resolve virtual method 16: Landroid/animation/ValueAnimator;.start()V 
10-30 14:54:55.261: D/dalvikvm(306): VFY: replacing opcode 0x6e at 0x0039 
10-30 14:54:55.281: I/dalvikvm(306): Could not find method android.animation.ValueAnimator.start, referenced from method org.osmdroid.views.MapController.zoomOutFixing 
10-30 14:54:55.281: W/dalvikvm(306): VFY: unable to resolve virtual method 16: Landroid/animation/ValueAnimator;.start()V 
10-30 14:54:55.281: D/dalvikvm(306): VFY: replacing opcode 0x6e at 0x0039 
10-30 14:54:55.331: I/org.osmdroid.views.MapView(306): Using tile source: [email protected] 
10-30 14:54:55.411: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(306): sdcard state: mounted 
10-30 14:54:55.431: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(306): sdcard state: mounted 
10-30 14:54:56.701: D/dalvikvm(306): GC_FOR_MALLOC freed 2917 objects/198880 bytes in 189ms 
10-30 14:54:57.322: D/dalvikvm(306): GC_FOR_MALLOC freed 2200 objects/114080 bytes in 117ms 
10-30 14:54:57.971: D/dalvikvm(306): GC_FOR_MALLOC freed 2010 objects/119912 bytes in 113ms 
10-30 14:54:58.752: D/dalvikvm(306): GC_FOR_MALLOC freed 1626 objects/122632 bytes in 205ms 
10-30 14:54:59.642: D/dalvikvm(306): GC_FOR_MALLOC freed 2119 objects/118352 bytes in 309ms 
10-30 14:55:00.672: D/dalvikvm(306): GC_FOR_MALLOC freed 2680 objects/147576 bytes in 137ms 
10-30 14:55:01.532: D/dalvikvm(306): GC_FOR_MALLOC freed 2817 objects/223456 bytes in 166ms 
10-30 14:55:02.291: I/org.osmdroid.tileprovider.MapTileProviderBase(306): rescale tile cache from 0 to 15 
10-30 14:55:02.341: D/dalvikvm(306): DexOpt: couldn't find field Landroid/graphics/BitmapFactory$Options;.inBitmap 
10-30 14:55:02.351: W/dalvikvm(306): VFY: unable to resolve instance field 33 
10-30 14:55:02.351: D/dalvikvm(306): VFY: replacing opcode 0x5b at 0x000b 
10-30 14:55:02.351: D/dalvikvm(306): VFY: dead code 0x000d-0010 in Lorg/osmdroid/tileprovider/BitmapPool;.applyReusableOptions (Landroid/graphics/BitmapFactory$Options;)V 
10-30 14:55:02.391: I/org.osmdroid.tileprovider.MapTileProviderBase(306): Finished rescale in 94ms 
10-30 14:55:02.641: D/dalvikvm(306): GC_EXTERNAL_ALLOC freed 3924 objects/224384 bytes in 206ms 
10-30 14:55:03.171: D/dalvikvm(306): GC_EXTERNAL_ALLOC freed 756 objects/167616 bytes in 171ms 
10-30 14:55:03.941: D/dalvikvm(306): GC_EXTERNAL_ALLOC freed 595 objects/63304 bytes in 320ms 
10-30 14:55:09.831: D/dalvikvm(306): GC_FOR_MALLOC freed 24577 objects/1568904 bytes in 255ms 
10-30 14:55:09.882: W/KeyCharacterMap(306): No keyboard for id 0 
10-30 14:55:09.892: W/KeyCharacterMap(306): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 
10-30 14:56:17.341: E/LocateMe(306): Could not get Geocoder data 
10-30 14:56:17.341: E/LocateMe(306): java.io.IOException: Service not Available 
10-30 14:56:17.341: E/LocateMe(306): at android.location.Geocoder.getFromLocation(Geocoder.java:117) 
10-30 14:56:17.341: E/LocateMe(306): at com.formation.mine.MainActivity.onLocationChanged(MainActivity.java:138) 
10-30 14:56:17.341: E/LocateMe(306): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:191) 
10-30 14:56:17.341: E/LocateMe(306): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:124) 
10-30 14:56:17.341: E/LocateMe(306): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:140) 
10-30 14:56:17.341: E/LocateMe(306): at android.os.Handler.dispatchMessage(Handler.java:99) 
10-30 14:56:17.341: E/LocateMe(306): at android.os.Looper.loop(Looper.java:123) 
10-30 14:56:17.341: E/LocateMe(306): at android.app.ActivityThread.main(ActivityThread.java:4627) 
10-30 14:56:17.341: E/LocateMe(306): at java.lang.reflect.Method.invokeNative(Native Method) 
10-30 14:56:17.341: E/LocateMe(306): at java.lang.reflect.Method.invoke(Method.java:521) 
10-30 14:56:17.341: E/LocateMe(306): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
10-30 14:56:17.341: E/LocateMe(306): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
10-30 14:56:17.341: E/LocateMe(306): at dalvik.system.NativeStart.main(Native Method) 
+0

내가 그렇게 호출 할 때, 메뉴의 "마 위치"부톤 섬을 누를 때 문제가 나타납니다 onLocationChanged() . – Mina

+0

참조 링크 : http://android-coding.blogspot.in/2012/06/example-of-implementing-openstreetmap.html – VVB

+0

Eclipse에서 MyMocationOverlay 유형이 사용되지 않는다고합니다. 그리고 나는 또한 많은 실수를 얻는다! 프로그램을 실행할 수 없습니다 – Mina

답변

0

나는 당신의 문제가이

java.io.IOException: Service not Available

시계 것 같다 1. 부팅 장치를 : 보인다 이러한 두 링크는 ​​일반적인 버그

Service not Available - Geocoder Android

Service not available while calling geoCoder.getFromLocation()

이러한 문제를 해결하기 위해 두 가지 일반적인 방법이다를 수 있습니다. 휴대 전화의 설정과 서비스가 2가

uses-permission android:name="android.permission.INTERNET"

를 추가하는 것이 어쩌면 당신 장애인 매니페스트

+0

답변 주셔서 감사합니다 그러나 나는 모든 것을 오프라인으로하고 싶습니다! 누군가가 내가 필요한 모든 정보를 텍스트 파일에 저장하라고 알려주지 만, 내 프로그램에서 Textfile을 호출하여 사용하려면 어떻게해야합니까? – Mina

+0

친애하는 미나 님, 도시의 모든 지오 코딩 정보를 수집하고 텍스트 파일에서 읽는 것에 대해 생각하지 마십시오 !!!!! 지오 코딩은 텍스트 파일에 몇 가지 이름과 위도 경도를 넣는 것이 아닙니다 !!!!!! 당신은 그것을 파싱하고 당신의 위치에 가장 가까운 위치를 찾은 다음 그 주소를 파싱해야합니다! 나는 불가능하다고 말하지 않지만 두 가지 중요한 일에주의를 기울이십시오! 1. 어디에서 정보를 수집하고 싶습니까?! 너 혼자해야 해! 2. 수집 후 파서를 작성해야합니다! –

+0

그래서 KML과 GPX는 무엇을 위해 사용됩니까? 실제로 osmbonuspack을 사용합니다! – Mina