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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:11:00+00:00 2026-06-17T12:11:00+00:00

I try to make a location app based on Android Maps API v2. I

  • 0

I try to make a location app based on Android Maps API v2. I add marker for my location point and a GroundOverlay circle for location accuracy. But GroundOverlay setPosition function sets slightly different. I can’t find why.

        package com.example.locator;

    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.BitmapDescriptorFactory;
    import com.google.android.gms.maps.model.GroundOverlay;
    import com.google.android.gms.maps.model.GroundOverlayOptions;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;

    import android.location.Criteria;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.content.Context;
    import android.support.v4.app.FragmentActivity;
    import android.view.Menu;

    public class MainActivity extends FragmentActivity implements LocationListener
     {
        GoogleMap mMap;
        Location                lastLocation = null;
        private LocationManager locationManager;
        private String provider;
        Marker curLoc = null; 
        GroundOverlay curLocCircle = null; 

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.activity_main);

            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(22.375675950685434, 29.83346939086914), 13));

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

            Criteria criteria = new Criteria();
            provider = locationManager.getBestProvider(criteria, false);
            Location location = locationManager.getLastKnownLocation(provider);

            if (location != null) {
                onLocationChanged(location);
            } else {
                //empty
            }
            locationManager.requestLocationUpdates(provider, 400, 1, this);
        } 

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }


        public void onLocationChanged(Location location) {
            if (location != null) {

                if (null != curLoc) {
                    curLoc.remove();
                }
                if (null != curLocCircle) {
                    curLocCircle.remove();
                }

                LatLng loc = new LatLng(location.getLatitude(),location.getLongitude());
                curLoc = mMap.addMarker(new MarkerOptions()
                .position(loc)
                .title("My location")
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.location32)));

                float accuracy = location.getAccuracy();

                curLocCircle = mMap.addGroundOverlay(new GroundOverlayOptions()
                        .image(BitmapDescriptorFactory
                                .fromResource(R.drawable.location_circle))
                        .position(loc, accuracy)
                        .transparency(0)
                );
                curLocCircle.setPosition(loc);
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 13));
            }
        }

        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

    }

When I pause app in debugger on line

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 13));

watches shows this data:

curLocCircle.getPosition()  lat/lng: (22.397815012772206,29.954818561673164)
location.getLatitude()      22.397815
location.getLongitude()     29.9548184
loc                         lat/lng: (22.397815,29.9548184)

curLocCircle.getPosition() somehow shows incorrect location write after setPosition(loc);
Please help me with that.

  • 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-06-17T12:11:01+00:00Added an answer on June 17, 2026 at 12:11 pm

    The problem was in marker anchor.
    Changed to:

    curLoc = mMap.addMarker(new MarkerOptions()
    .position(loc)
    .anchor(0.5f, 0.5f)
    .title("My location")
    .icon(BitmapDescriptorFactory.fromResource(R.drawable.location32)));
    

    And everything is fine. I still don’t get why location of GroundOverlay differs from defined location, but I don’t care. It looks good.

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

Sidebar

Related Questions

I try to make an animation with an image in my view but it
I try to make an Android application which communicates with a non-standard ISO15693 (NFC-V)
i try to make a foreach loop in c#. In textbox1 is the location
I'm trying to make a button in my app open the google maps app
Trying to create a Django app based off the tutorial but using a different
I am trying to make an app that will send your gps location to
i make a location application on android. here's the code for acquiring lat and
I am trying to make a game. I try to use GridView but wonder
I try to make my ListBox connected to ObservaleCollection be more efficient so for
I try to make an ActiveX by C# with COM-visible. It is a Windows

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.