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

  • SEARCH
  • Home
  • 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 7618855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:30:44+00:00 2026-05-31T03:30:44+00:00

i have questions that i am really need some help on it: i develop

  • 0

i have questions that i am really need some help on it:
i develop application and i want :

1-retrieve the user location and show it in the map.
2- the user can put pin in any place in the map and i should take the coordination to this pin and store it in variable

Note:my application in 2.1 should i use google API? if yes, does the google API support any activity rather than maps?

i search in google and find this code :

package com.java.locate;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;



  public class AndroidLbsGeocodingProjectActivity extends Activity {
   /** Called when the activity is first created. */
    private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
    private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
    protected LocationManager locationManager;
    protected Button retrieveLocationButton;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button);

            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            locationManager.requestLocationUpdates(
                        LocationManager.GPS_PROVIDER,
                    MINIMUM_TIME_BETWEEN_UPDATES,
                        MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
                   new MyLocationListener()
                );

            retrieveLocationButton.setOnClickListener(new OnClickListener() {

                    public void onClick(View v) {
                        showCurrentLocation();
                    }
            });       

            }   

            protected void showCurrentLocation() {

                Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                if (location != null) {
                    String message = String.format(
                            "Current Location \n Longitude: %1$s \n Latitude: %2$s",
                            location.getLongitude(), location.getLatitude()
                    );
                    Toast.makeText(AndroidLbsGeocodingProjectActivity.this, message,
                            Toast.LENGTH_LONG).show();
                }

            }  

            private class MyLocationListener implements LocationListener {

                public void onLocationChanged(Location location) {
                    String message = String.format(
                        "New Location \n Longitude: %1$s \n Latitude: %2$s",
                            location.getLongitude(), location.getLatitude()
                    );
                    Toast.makeText(AndroidLbsGeocodingProjectActivity.this, message, Toast.LENGTH_LONG).show();
                }

                public void onStatusChanged(String s, int i, Bundle b) {
                    Toast.makeText(AndroidLbsGeocodingProjectActivity.this, "Provider status changed",
                            Toast.LENGTH_LONG).show();
                }

            public void onProviderDisabled(String s) {
                    Toast.makeText(AndroidLbsGeocodingProjectActivity.this,
                            "Provider disabled by the user. GPS turned off",
                            Toast.LENGTH_LONG).show();
                }

                public void onProviderEnabled(String s) {
                    Toast.makeText(AndroidLbsGeocodingProjectActivity.this,
                            "Provider enabled by the user. GPS turned on",
                            Toast.LENGTH_LONG).show();
                }

        }




}

this is another code, this by using google API, but i have 2 issues in using this code :
1-it does not retrieve the user location, it is just show me the maps.
2-does google API working with another activity not just map?

  package our.google.maps;

  import java.util.List;
  import java.util.Locale;

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

  import android.app.AlertDialog;
  import android.content.DialogInterface;
  import android.location.Geocoder;
  import android.location.Location;
  import android.location.LocationListener;
  import android.os.Bundle;
  import android.view.MotionEvent;
  import android.widget.Toast;

  public class MapsActivity extends MapActivity {
/** Called when the activity is first created. */
long start;
long stop;
MyLocationOverlay compass;
MapController controller;
MapView map;
  //136
int x,y;
GeoPoint touchedPoint;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    map=(MapView) findViewById(R.id.mvMain);
    map.setBuiltInZoomControls(true);
    Touchy t = new Touchy();
    List<Overlay> overlaylist= map.getOverlays();
    overlaylist.add(t);
    compass = new MyLocationOverlay (MapsActivity.this, map);
    overlaylist.add(compass);
    //map controller to go to Specific Location n36eeh el 6ol & el 3r'9  135

    controller=map.getController();
    GeoPoint point = new GeoPoint (51643234 , 7848593);
    controller.animateTo(point);
    controller.setZoom(6);

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    compass.disableCompass();

    super.onPause();
  }
@Override
protected void onResume() {
    // TODO Auto-generated method stub
    compass.enableCompass();
    super.onResume();
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
class Touchy extends Overlay {
    public boolean onTouchEvent(MotionEvent e,MapView m){
        if(e.getAction() == MotionEvent.ACTION_DOWN){
            start = e.getEventTime();
            x = (int) e.getX();
            y = (int) e.getY();
            touchedPoint = map.getProjection().fromPixels(x, y);

        }
        if (e.getAction() == MotionEvent.ACTION_UP) {
            stop =e.getEventTime();
        }
        if(stop - start >1500) {
            AlertDialog alert = new AlertDialog.Builder(MapsActivity.this).create();
        alert.setTitle("Pick an option");
        alert.setMessage(" i told u to pick an option"); 
        alert.setButton("place a pin", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        } );

     alert.setButton2("get an address", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Geocoder geocode = new Geocoder   (getBaseContext(),Locale.getDefault());
        try {

        }
        finally{}}}
         );

      alert.setButton3("option3 ", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub

}
    } );
     alert.show();
      return true;
        }
    return false;   
    }
}
private class MyLocationListener implements LocationListener{


    public void onLocationChanged1(Location location) {
        String message = String.format(
            "New Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude()
        );
        Toast.makeText(MapsActivity.this, message, Toast.LENGTH_LONG).show();
    }

    public void onStatusChanged(String s, int i, Bundle b) {
        Toast.makeText(MapsActivity.this, "Provider status changed",
                Toast.LENGTH_LONG).show();
    }

public void onProviderDisabled(String s) {
        Toast.makeText(MapsActivity.this,
                "Provider disabled by the user. GPS turned off",
                Toast.LENGTH_LONG).show();
    }

    public void onProviderEnabled(String s) {
        Toast.makeText(MapsActivity.this,
                "Provider enabled by the user. GPS turned on",
                Toast.LENGTH_LONG).show();
    }

    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

    }

 }

 }

also,if my code is not correct, can you please give me the correct coed?
StackOverFlow members you are My HERO! help me PLEASE!

  • 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-31T03:30:46+00:00Added an answer on May 31, 2026 at 3:30 am

    You can Use Google Maps.
    You will require Map Api key.
    If you are coding Using Eclipse then you can follow the procedure given on link
    http://mobiforge.com/developing/story/using-google-maps-android

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've some questions .. and I really need your help. I have an application.
I have some questions about basic CSS that I was unable to understand or
I have some basic questions around understanding fundamentals of Performance testing. I know that
I have some data stored in a DB that I want to process. DB
I need some help with floating point numbers...please! Here's the thing, I have code
This is a (hopefully) really simple question - I have been told recently that
This is a little different than the questions that have already been asked on
There have been a couple of questions that sort of dealt with this but
I have javascript string variable with var sttr=We prefer questions that can be answered
Ok, have a bunch of questions that I have been thinking about the past

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.