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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:19:40+00:00 2026-05-24T08:19:40+00:00

I’m using GPS to get my location but this code shows my location in

  • 0

I’m using GPS to get my location but this code shows my location in Pacific although I’m in middle east …

another functionality of this code is to add an icon ( marker ) in the place I touch on the screen , according my code, does it works fine ?!

here is my code :

package com.adhamenaya.android;

import java.util.List;

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 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;

public class MapApp extends MapActivity {

    private MapView mapView;
    private MapController mapController;
    private LocationManager locationManager;
    private GeoPoint p;
    List<Overlay> listOfOverlays ;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initLayout();
        initMap();
        listOfOverlays = mapView.getOverlays();        
    }

    private void initLayout(){
         mapView = (MapView) findViewById(R.id.mapview);

    }
    private void initMap(){
        mapView.setBuiltInZoomControls(true);
        mapView.setStreetView(true);
        mapController=mapView.getController();
        mapController.setZoom(10);// 1 is world view
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0, 0, new GeoUpdateHandler());

    }      
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    class MapOverlay extends com.google.android.maps.Overlay
    {
        private GeoPoint p;
        private int res;

        public MapOverlay(GeoPoint p,int res){
            this.p=p;
            this.res=res;
        }

    @Override
     public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
     {
         super.draw(canvas, mapView, shadow);                   

         //---translate the GeoPoint to screen pixels---
         Point screenPts = new Point();
         mapView.getProjection().toPixels(p, screenPts);

         //---add the marker---
         Bitmap bmp = BitmapFactory.decodeResource(getResources(),res);            
         canvas.drawBitmap(bmp, screenPts.x, screenPts.y-20, null);         
         return true;
     }

        @Override
        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());
                 mapController.animateTo(p);
                 MapOverlay mapOverlay = new MapOverlay(p,R.drawable.redicon);
                 listOfOverlays.add(mapOverlay);        
                 mapView.invalidate();
            }                            
            return false;
        }        
    }

    class GeoUpdateHandler implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
            int lat=(int)(location.getLatitude()*1E6);
            int lng=(int)(location.getLongitude()*1E6);         
            GeoPoint p=new GeoPoint(lat,lng);
            mapController.animateTo(p);
            MapOverlay mapOverlay = new MapOverlay(p,R.drawable.blueicon);
            listOfOverlays.add(mapOverlay);        
            mapView.invalidate();

        }

        @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

        }

}

}
  • 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-24T08:19:40+00:00Added an answer on May 24, 2026 at 8:19 am

    Did you try running it on an actual device or just the Emulator? I had experienced the same issue, the location co-ordinates are updated using the ISP’s IP address in case GPS isn’t available such as in case of emulator. There age high chances the code will run fine on a device.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.