android - eclipse: display google maps using coordinates obtained using gps

别说谁变了你拦得住时间么 提交于 2019-12-04 16:58:40

Here's a full-blown tutorial on that: http://www.codeproject.com/Articles/112044/GPSLocator-App-to-Find-Current-Nearest-Location-us

But come on, I found that by entering "android how to show gps location on google map", please, google more thoroughly and go through tutorials before posting such simple questions :)

Assuming that you are using MapView, the simplest thing to do is add an instance of MyLocationOverlay to the map, as Android will handle displaying the user's location for you.

map=(MapView)findViewById(R.id.whatever_your_mapview_id_is);
map.getOverlays().add(new MyLocationOverlay(this, map));

If for some reason you want to do that yourself rather than use the built-in facility, you can create your own ItemizedOverlay to display the point, and add an instance of your own custom overlay to the MapView.

It's the best to use MyLocationOverlay if you want to display user's current location. However you have alternative of:

map.animateTo(GeoPoint);

Assuming that u've defined your mapview and mapcontroller

for that, first you neeed suscribe to the location update in your OnCreate method like that: the code belows requests update every 1000ms or 10m

LocationManager lm;
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10f, this);

below you is my way to update my position on the map

@Override
GeoPoint p,P2, p3;
double lat=53,  double lng=4;
    public void onLocationChanged(Location location) {
        Log.v(tag, "Location Changed");

        lat= (int) (location.getLatitude());
        lng= (int) (location.getLongitude());

        sb = new StringBuilder(512);

        noOfFixes++;

        p = new GeoPoint(
                (int) (location.getLatitude()*1E6), 
              (int) (location.getLongitude()*1E6));
        mapController.animateTo(p);
        mapController.setCenter(p);

        Toast.makeText(this, "Lat= " + lat + " Long= " + lng, Toast.LENGTH_SHORT).show();




    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!