IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants graphiques Android Discussion :

Soucis avec code pour avoir un dessin de son trajet


Sujet :

Composants graphiques Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2021
    Messages : 51
    Points : 11
    Points
    11
    Par défaut Soucis avec code pour avoir un dessin de son trajet
    Bonjour, je vous contacte car j'ai un soucis avec un code. Je n'arrive pas à le faire marcher malgré que j'ai bien utilisez la clé API. Voici le code ci joint. Ce serait surtout de la visualisation de voir comment cela marche car je dois faire le meme type de code en utilisant l'accéléromètre et le gyroscope (GPS pour la localisation) du téléphone

    MainActivity.java :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    public class MainActivity extends AppCompatActivity implements
        OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        com.google.android.gms.location.LocationListener {
     
    Button btnStart;
    int flag;
     
    private GoogleMap mMap;
     
    private Polyline gpsTrack;
    private SupportMapFragment mapFragment;
    private GoogleApiClient googleApiClient;
    private LatLng lastKnownLatLng;
     
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
        btnStart = findViewById(R.id.btnStart);
     
        mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
     
        if (googleApiClient == null) {
            googleApiClient = new GoogleApiClient.Builder(this)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .build();
        }
     
    }
     
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
     
        PolylineOptions polylineOptions = new PolylineOptions();
        polylineOptions.color(Color.RED);
        polylineOptions.width(10);
        gpsTrack = mMap.addPolyline(polylineOptions);
     
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != 
    PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 
    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        mMap = googleMap;
     
        mMap.setMinZoomPreference(6.6f);
        mMap.setMaxZoomPreference(20.20f);
     
        mMap.setMyLocationEnabled(true);
        mMap.getUiSettings().setMyLocationButtonEnabled(true);
     
        LocationServices.getFusedLocationProviderClient(this).getLastLocation()
                .addOnSuccessListener(new OnSuccessListener<Location>() {
                    @Override
                    public void onSuccess(Location location) {
                        if (location != null){
                            Log.i("teste", "deu");
     
                             LatLng atual = new LatLng(location.getLatitude(), location.getLongitude());
                             mMap.addMarker(new MarkerOptions().position(atual).title("Localizção 
    atual"));
                             mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(atual, 15));
     
                        }else {
                            Log.i("teste", "n deu");
                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
     
                    }
                });
     
    }
     
     
    @Override
    protected void onStart() {
        googleApiClient.connect();
        super.onStart();
    }
     
    @Override
    protected void onStop() {
        googleApiClient.disconnect();
        super.onStop();
    }
     
    @Override
    protected void onPause() {
        super.onPause();
        stopLocationUpdates();
    }
     
    @Override
    public void onResume() {
        super.onResume();
        if (googleApiClient.isConnected()) {
            //startLocationUpdates();
        }
    }
     
    @Override
    public void onConnected(@Nullable Bundle bundle) {
        if (googleApiClient.isConnected()) {
            //startLocationUpdates();
        }
    }
     
    @Override
    public void onConnectionSuspended(int i) {
     
    }
     
    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
     
    }
     
    @Override
    public void onLocationChanged(Location location) {
        lastKnownLatLng = new LatLng(location.getLatitude(), location.getLongitude());
        updateTrack();
    }
     
    protected void startLocationUpdates() {
        LocationRequest locationRequest = new LocationRequest();
        locationRequest.setInterval(15 * 1000);
        locationRequest.setFastestInterval(5 * 1000);
        locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
     
     
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != 
    PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 
    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, 
    this);
    }
     
    protected void stopLocationUpdates() {
        LocationServices.FusedLocationApi.removeLocationUpdates(
                googleApiClient, this);
    }
     
    private void updateTrack() {
        List<LatLng> points = gpsTrack.getPoints();
        points.add(lastKnownLatLng);
        gpsTrack.setPoints(points);
     
    }
     
    public void socorro(View v) {
     
        switch (v.getId()) {
            case R.id.btnStart:
                startLocationUpdates();
                btnStart.setBackgroundResource(R.drawable.stop);
                break;
     
        }
    }
    }


    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
     
    <fragment
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />
     
    <LinearLayout
     
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="70dp">
    <Button
        android:id="@+id/btnStart"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:onClick="socorro"
        android:background="@drawable/rec"
     
        />
     
    </LinearLayout>
     
    </RelativeLayout>

    Voilà voilà en espérant pourvoir être aidé car c'est la première fois que je fais cela.

  2. #2
    Membre averti
    Homme Profil pro
    Architecte technique
    Inscrit en
    Mai 2020
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Mai 2020
    Messages : 325
    Points : 436
    Points
    436
    Par défaut
    Bonjour,

    Ce serait bien d'indiquer le résultat attendu et ce que vous avez actuellement, ça aiderais les autres à comprendre votre problème.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2021
    Messages : 51
    Points : 11
    Points
    11
    Par défaut
    Voici les problèmes que j ai pour le code
    Nom : 2022-03-21.png
Affichages : 66
Taille : 332,0 KoNom : 2022-03-21 (1).png
Affichages : 66
Taille : 247,4 Ko

    Et voici les résultats que je devrais avoir :
    Nom : 4P6En.png
Affichages : 55
Taille : 122,7 Ko

    Je dois arriver à le faire avant demain et je bug bcp la dessus en espérant pouvoir être aider

Discussions similaires

  1. Soucis de code pour mon site !
    Par 7voix dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 20/09/2010, 01h55
  2. Filtrer avec date pour avoir YTD & Last YTD
    Par jezfox dans le forum Cognos
    Réponses: 1
    Dernier message: 21/06/2010, 14h47
  3. Probleme avec code pour des btn
    Par abyssal31 dans le forum ActionScript 1 & ActionScript 2
    Réponses: 2
    Dernier message: 26/01/2010, 14h28
  4. [JQuery] Soucis avec Jeditable pour Jquery
    Par PseT34 dans le forum jQuery
    Réponses: 1
    Dernier message: 29/12/2007, 23h25
  5. Probleme avec code pour fond musical
    Par Yanout dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 05/09/2007, 17h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo