Displaying User's Location

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Displaying User's Location

Postby MizoRedDevil » Mon Mar 07, 2011 11:09 pm

Hi,
I'm a new coming in the world of android, I wanted to make a simple application that can display my location in real time :), but i can't have a result :( :( here's my code :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.louky.GPS;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.location.Location;
  5. import android.location.LocationListener;
  6. import android.location.LocationManager;
  7. import android.location.LocationProvider;
  8. import android.os.Bundle;
  9. import android.widget.Toast;
  10. public class SampleGPS extends Activity
  11. {
  12.         private LocationManager locationManager;
  13.         private LocationListener locationListener;
  14.         @Override
  15.         public void onCreate(Bundle savedInstanceState)
  16.         {
  17.                 super.onCreate(savedInstanceState);
  18.                 setContentView(R.layout.main);
  19.                 System.out.println("etape une");
  20.                 locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  21.                 System.out.println("etape deux");
  22.                 locationListener = new MyLocationListener();
  23.                 System.out.println("etape trois");
  24.                 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
  25.                 System.out.println("etape quatre");
  26.         }
  27.         private class MyLocationListener implements LocationListener
  28.         {
  29.                 public void onLocationChanged(Location loc)
  30.                 {
  31.                         System.out.println("Position Changed");
  32.                         if (loc != null)
  33.                         {
  34.                                 Toast.makeText(getBaseContext(), "Localisation actuelle :\n Lat: " + loc.getLatitude() + "  Lng: " + loc.getLongitude(),Toast.LENGTH_SHORT).show();
  35.                         }
  36.                 }
  37.                 public void onProviderDisabled(String provider)
  38.                 {
  39.                         System.out.println(provider+" Est Désactivé");
  40.                 }
  41.                 public void onProviderEnabled(String provider)
  42.                 {
  43.                         System.out.println(provider+" Est Activé");
  44.                 }
  45.                 public void onStatusChanged(String provider, int status,Bundle extras)
  46.                 {
  47.                 }
  48.         }
  49. }
Parsed in 0.054 seconds, using GeSHi 1.0.8.4


and here's what the LogCat displays to me :
Image
What should I do ???? :s
HELP WANTED PLEASE :(
MizoRedDevil
Freshman
Freshman
 
Posts: 3
Joined: Mon Mar 07, 2011 11:01 pm

Top

Re: Displaying User's Location

Postby eyespyus » Tue Mar 08, 2011 1:37 am

Mizo,

The code works no problems. Two small items to note:

1. Emulator does not have a real GPS and will never provide location updates. You can fake it using strategies here:

http://developer.android.com/guide/topi ... l#MockData

2. You will generate so many toast messages on a real device that the toast framework will not be able to keep up.

eye
User avatar
eyespyus
Freshman
Freshman
 
Posts: 7
Joined: Fri Mar 05, 2010 9:31 pm

Re: Displaying User's Location

Postby MizoRedDevil » Tue Mar 08, 2011 9:15 am

Oh, thanks, so if I get it, I can't get my current position if i do not have a real GPS isn't it ?
There's not a way to do that with wifi ??
MizoRedDevil
Freshman
Freshman
 
Posts: 3
Joined: Mon Mar 07, 2011 11:01 pm

Re: Displaying User's Location

Postby eyespyus » Tue Mar 08, 2011 3:13 pm

Nothing will work in the Emulator.

If you have a real phone wihout GPS then you can get location from the cell phone network (relative location to the nearest cell tower).
User avatar
eyespyus
Freshman
Freshman
 
Posts: 7
Joined: Fri Mar 05, 2010 9:31 pm

Re: Displaying User's Location

Postby MizoRedDevil » Tue Mar 08, 2011 4:48 pm

that's cool, i tried to choose the network_provider but it's always disabled :((
how to enable it please ? :(
MizoRedDevil
Freshman
Freshman
 
Posts: 3
Joined: Mon Mar 07, 2011 11:01 pm

Re: Displaying User's Location

Postby hmkh » Mon Apr 04, 2011 3:42 pm

Hi,
I do know that you have sovled your problem or not, if not you should have a look at this link, it provides you how to simulate GPS on emulator.
http://www.devx.com/wireless/Article/39239
hmkh
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Mar 30, 2011 12:11 pm

Top

Re: Displaying User's Location

Postby kevat_patel » Tue Apr 05, 2011 7:59 am

hi MizoRedDevil

write follow setting any thing in AndroidManifest.xml

Uri uri= Uri.parse("geo:0,0?q=Gujarat+India");

Intent intent = new Intent(Intent.ACTION_VIEW,uri);

intent.putExtra(SearchManager.QUERY, "Bhavnagar");

startActivity(intent);
kevat_patel
Developer
Developer
 
Posts: 46
Joined: Fri Mar 25, 2011 6:59 am

Re: Displaying User's Location

Postby chaitu45 » Wed Apr 13, 2011 3:42 pm

I'm curious. What's the advantage of creating your own overlay when the one provided by google does exactly that?
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MyLocationOverlay.html
chaitu45
Experienced Developer
Experienced Developer
 
Posts: 65
Joined: Tue Sep 14, 2010 9:36 pm
Location: Cincinnati, Ohio

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests