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 6888227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:59:06+00:00 2026-05-27T05:59:06+00:00

* Please tell me how to set the Geo-point to current location on start

  • 0

*Please tell me how to set the Geo-point to current location on start of program? I want to set an overlay balloon to current location of user in emulator on starting of the program marked as “you are here”. My Code is here-*

package com.jbb;

import java.util.List;
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.Overlay;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;


public class jbb_latitudeActivity extends MapActivity 
{    
    LocationManager lm;
    MyLocationListener locationListener;
    MapView mapView;
    MapController mc;
    GeoPoint geoPoint;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        try{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
        geoPoint = new GeoPoint( (int) (12.949997* 1E6), (int) (80.140213 * 1E6));
        mapView = (MapView) findViewById(R.id.name);
        mc = mapView.getController();
        mc.animateTo(geoPoint);
        mapView.setClickable(true);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(true);
        mapView.setTraffic(true);
        List<Overlay> overlays = mapView.getOverlays();
                overlays.clear();
        overlays.add(new MyLocationListener());
        //---use the LocationManager class to obtain GPS locations---
        lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);    
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new MyLocationListener());
        }
    catch (Exception e) {
        // TODO: handle exception
        Toast.makeText(getApplicationContext(),e.toString() , 1).show();
    }

        }
   @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }        

    private class MyLocationListener extends Overlay implements LocationListener 
    {
          public void draw(Canvas canvas, MapView mapView, boolean shadow) {                              // 1
            super.draw(canvas, mapView, shadow);
                if (!shadow) {                                                                              // 2
                    Point point = new Point();
                    mapView.getProjection().toPixels(geoPoint, point);                                      // 3
                    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker_default);   // 4
                    int x = point.x - bmp.getWidth() / 2;                                                   // 5                   inty=point.ybmp.getHeight();                                                      // 6         canvas.drawBitmap(bmp,x,y,null);                                                     // 7
                }
            }
         public boolean onTouchEvent(MotionEvent event, MapView mapView) 
        {   
            //---when user lifts his finger---
            if (event.getAction() == 1) {                
                GeoPoint p = mapView.getProjection().fromPixels(
                    (int) event.getX(),
                    (int) event.getY());
            }                            
            return false;
        }
         public boolean onTap(GeoPoint point, MapView mapView) 
         {

           String msg = "Lat:: " + point.getLatitudeE6()/1E6 + " - " + 
                        "Lon:: " + point.getLongitudeE6()/1E6;
          Toast.makeText(mapView.getContext(), msg,1).show();
          return true;
         }
        @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {                
                Toast.makeText(mapView.getContext(), 
                    "Location changed : Lat: " + loc.getLatitude() + 
                    " Lng: " + loc.getLongitude(), 
                    1).show();

                GeoPoint p = new GeoPoint(
                        (int) (loc.getLatitude() * 1E6), 
                        (int) (loc.getLongitude() * 1E6));
                mc.animateTo(p);
                mc.setZoom(15);                
                mapView.invalidate();    
            }
        }
        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
            Toast.makeText(mapView.getContext(), "hee", 1).show();
        }
        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
            Toast.makeText(mapView.getContext(), "hee", 1).show();
        }
        @Override
        public void onStatusChanged(String provider, int status, 
            Bundle extras) {
            // TODO Auto-generated method stub
            Toast.makeText(mapView.getContext(), "hee", 1).show();
        }
    }    
}
  • 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-27T05:59:06+00:00Added an answer on May 27, 2026 at 5:59 am

    First,you should have added the permission

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission> 
    

    Then try,

    Criteria criteria = new Criteria();
    String bestProvider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(bestProvider); 
    locationManager.requestLocationUpdates(bestProvider, 0, 0, new TestLocationListener());
    

    instead of,

    lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);    
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,new MyLocationListener());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Almighty Gurus, Please tell me, I want to know can comparison sm. set of
Can anyone please tell me whether the <location path= works when we set <authentication
Can any one please tell me how to set notifications for different values at
Can you please tell me how can I set a global #define in my
Please tell me if I got this wrong. Anchor point is like a movable
Can someone please tell me why, even though I've set my Window to SizeToContent
Can someone please tell me what event occurs when a user enters a page
Can somebody please tell me what is wrong with the following applescript set sourceFile
I'm new to Wicket. Can someone please tell me how to dynamically set required
Could you please tell me how to effectively allow the user to import their

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.