Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4099518
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:26:40+00:00 2026-05-20T20:26:40+00:00

Location.java package com.localisation; import java.io.IOException; import java.util.List; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import

  • 0

Location.java

package com.localisation;

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

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
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.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class localisation extends Activity implements OnClickListener, LocationListener{
    private LocationManager lManager;
    private Location location;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //On spécifie que l'on va avoir besoin de gérer l'affichage du cercle de chargement
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.main);

        //On récupère le service de localisation
        lManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);


        //On affecte un écouteur d'évènement aux boutons
        findViewById(R.id.obtenir_position).setOnClickListener(this);

    }

        //Méthode déclencher au clique sur un bouton
    public void onClick(View v) {
            obtenirPosition();
        }
    }

    private void afficherLocation() {
        //On affiche les informations de la position a l'écran
        ((TextView)findViewById(R.id.latitude)).setText(String.valueOf(location.getLatitude()));
        ((TextView)findViewById(R.id.longitude)).setText(String.valueOf(location.getLongitude()));
        ((TextView)findViewById(R.id.altitude)).setText(String.valueOf(location.getAltitude()));
    }

    public void onProviderDisabled(String provider) {
        //Lorsque la source (GSP ou réseau GSM) est désactivé
        Log.i("Tuto géolocalisation", "La source a été désactivé");
        //...on affiche un Toast pour le signaler à l'utilisateur
        Toast.makeText(localisation.this,
                String.format("La source \"%s\" a été désactivé", provider),
                Toast.LENGTH_SHORT).show();
        //... et on spécifie au service que l'on ne souhaite plus avoir de mise à jour
        lManager.removeUpdates(this);
        //... on stop le cercle de chargement
        setProgressBarIndeterminateVisibility(false);
    }

    public void onProviderEnabled(String provider) {
        Log.i("Tuto géolocalisation", "La source a été activé.");
    }
    public void onStatusChanged(String provider, int status, Bundle extras) {
        Log.i("Tuto géolocalisation", "Le statut de la source a changé.");
    }

}

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView android:text="Latitude" 
        android:id="@+id/TextView01"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:gravity="center" 
        android:layout_marginLeft="10dip" />

    <EditText android:text="0.0" 
        android:id="@+id/latitude"
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true"
        android:editable="false"
        android:focusable="false"
        android:gravity="center" 
        android:layout_marginRight="10dip"
        android:layout_width="150dip" />

    <TextView android:text="Longitude" 
        android:id="@+id/TextView02"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/longitude" 
        android:layout_alignTop="@+id/longitude"
        android:gravity="center" 
        android:layout_marginLeft="10dip" />

    <EditText android:text="0.0" 
        android:id="@+id/longitude"
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true"
        android:editable="false"
        android:focusable="false"
        android:gravity="center" 
        android:layout_marginRight="10dip"
        android:layout_width="150dip" 
        android:layout_below="@+id/latitude" />

    <TextView android:text="Altitude" 
        android:id="@+id/TextView03"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/altitude" 
        android:layout_alignTop="@+id/altitude"
        android:gravity="center" 
        android:layout_marginLeft="10dip" />

    <EditText android:text="altitude" 
        android:id="@+id/altitude"
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true"
        android:editable="false"
        android:focusable="false"
        android:gravity="center" 
        android:layout_marginRight="10dip"
        android:layout_below="@+id/TextView02" 
        android:layout_width="150dip" />

    <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/TextView03" 
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dip">


        <Button android:layout_height="wrap_content" 
            android:id="@+id/obtenir_position"
            android:text="Obtenir Position" 
            android:layout_width="100dip" />

    </LinearLayout>
</RelativeLayout>

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.localisation"
      android:versionCode="1"
      android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".localisation"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    </application>
</manifest>

i have a problem in those codes. My goal is determine my position (longitude, latitude and altitude.

In a database i have some places defined by (longitude, latitude and altitude and i want to determine the most near place. (with google Map API (without displaying the map)

Can you help me please and explain me in details what i do now?

Thank you very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:26:40+00:00Added an answer on May 20, 2026 at 8:26 pm

    I am using this code to get the Latitude and longitude of current location:

    LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locationListener);
    Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    
    double latitude=0;
    double longitude=0;
    latitude = location.getLatitude();
    longitude = location.getLongitude();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package com.satyam.curlocation; import android.app.Activity; import android.content.Context; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.os.Bundle;
I'm running the following code.... package com.dc; import android.app.Activity; import android.content.Intent; import android.net.Uri; import
package com.crumbin.tabs; import java.util.ArrayList; import java.util.HashMap; import org.apache.http.client.HttpClient; import android.content.Context; import android.database.Cursor; import android.location.Location;
This is my GPSLoggerservice code: package com.mygps.android; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import
I have written following code to get location name package demo.gps.locname; import java.io.IOException; import
I want to get the address of location, I tried: package com.spot.prototype; import android.os.Bundle;
trying to find the current location of my device.code is here. package com.example.location; import
When I add this code to my Android 2.1 Java app, it fails: db=SQLiteDatabase.openOrCreateDatabase(Locations,
I made a really simple java example with two files: Dog.java contains: package com.greg.dog;
In my SVN java source files are under src/java/com/... location. When I create the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.