The Friend Finder - MapActivity using GPS - FULL SOURCE

Tutorials that use the MapActivity. Many using GPS functionality.

Postby plusminus » Sun Mar 09, 2008 1:26 pm

Hello pavanch,

yes the Notes-section is gone.

Your idea is not completely wrong. Somewhere I read, that when the user types an address there, it also gets internally converted to Lat/Lng.
I've had no time yet to determine where the Address-data gets stored to.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby slim » Sat Mar 22, 2008 6:29 am

I made a few mods and got it to work on the new api:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         private void refreshFriendsList(long maxDistanceInMeter){
  3.  
  4.                 String columns[]= new String[] {
  5.  
  6.                                 android.provider.BaseColumns._ID,
  7.  
  8.                                 android.provider.Contacts.ContactMethods.POSTAL_LOCATION_LATITUDE,
  9.  
  10.                                 People.NAME
  11.  
  12.                                 };
  13.  
  14.                
  15.  
  16.                
  17.  
  18.                 /*
  19.  
  20.                  * make sure you have a contact at this adddress
  21.  
  22.                  * if using the geocoder: 1600 Pennsylvania Avenue, Washington DC
  23.  
  24.                  * and the geodb file filled up
  25.  
  26.                  */
  27.  
  28.                 Geocoder myCoder = new Geocoder();
  29.  
  30.                 // you could get an API @ google and recompile the gmmgeocoder class, with modified
  31.  
  32.                 // code to use your account ... that might work
  33.  
  34.                 //GmmGeocoder myCoder2 = new GmmGeocoder(Locale.getDefault());
  35.  
  36.                
  37.  
  38.                 Cursor c = managedQuery(
  39.  
  40.                                 android.provider.Contacts.ContactMethods.CONTENT_URI,
  41.  
  42.                                 columns,
  43.  
  44.                                 null,  
  45.  
  46.                                 People.NAME + " ASC");
  47.  
  48.                 startManagingCursor(c);
  49.  
  50.  
  51.  
  52.                 //it puts the address in the lat column
  53.  
  54.                 int latColumn = c.getColumnIndex(ContactMethods.POSTAL_LOCATION_LATITUDE);// c.getColumnIndex(People.NOTES);
  55.  
  56.                 int nameColumn = c.getColumnIndex(People.NAME);
  57.  
  58.  
  59.  
  60.                 // Moves the cursor to the first row
  61.  
  62.                 // and returns true if there is sth. to get
  63.  
  64.                 if (c.first()) {
  65.  
  66.  
  67.  
  68. outerloop:
  69.  
  70.                         do {   
  71.  
  72.                                 Location friendLocation = null;
  73.  
  74.                                
  75.  
  76.                                 //this contains the address
  77.  
  78.                                 String address = c.getString(latColumn);
  79.  
  80.                                
  81.  
  82.                                 String name = c.getString(nameColumn);
  83.  
  84.                                
  85.  
  86.                                 // check if we havent already added friend
  87.  
  88.                                 // They recommend avoiding for each loops for optimality,...
  89.  
  90.                                 for(int i=0;i<nearFriends.size() ; i++)
  91.  
  92.                                         if(nearFriends.get(i).itsName.equals(name))
  93.  
  94.                                         {
  95.  
  96.                                                 c.next();      
  97.  
  98.                                                 break outerloop;
  99.  
  100.                                         }
  101.  
  102.                                 // get friend's coordinates
  103.  
  104.                                 try{
  105.  
  106.                                         Address friendsAddr[]= myCoder.getFromLocationName(address, 0,0,180,360);
  107.  
  108.                                         friendLocation= new Location();
  109.  
  110.                                         friendLocation.setLatitude(friendsAddr[0].getLatitude());
  111.  
  112.                                         friendLocation.setLongitude(friendsAddr[0].getLongitude());
  113.  
  114.                                 }
  115.  
  116.                                 catch(Exception e){
  117.  
  118.                                 }
  119.  
  120.                                                        
  121.  
  122.                        
  123.  
  124.                                 if(friendLocation != null
  125.  
  126.                                                 /*&& this.myLocation.distanceTo(friendLocation) < maxDistanceInMeter*/){
  127.  
  128.                                         String friendName = c.getString(nameColumn);
  129.  
  130.                                         nearFriends.add(new Friend(friendLocation, friendName));
  131.  
  132.                                 }
  133.  
  134.                         } while (c.next());
  135.  
  136.                 }
  137.  
  138.         }
  139.  
  140.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


I convert the address to a lat/long manually though, i don't know where it stores it if it does it automatically?
slim
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Mar 22, 2008 6:19 am

Postby pavanch » Thu Mar 27, 2008 5:15 am

hey slim..thanks for working on this issue. I havent tried to get this code to run my machine yet, i sure will and i'll let you know..
pavanch
Freshman
Freshman
 
Posts: 2
Joined: Fri Mar 07, 2008 7:15 pm

Postby inter » Sat Apr 05, 2008 11:49 am

Hi ,all

I am facing a problem with M5 . when i use this code as tutorial of plusminus , i see the error message IndexOutOfBound .I correct it by this code LocationProvider provider=this.myLocationManager.getProvider("gps");
I see the error : NULL POINTER .How to correct it?

Thank you

Regard
inter
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 21, 2008 10:13 am

Postby plusminus » Sat Apr 05, 2008 12:04 pm

Hello inter,

did you check whether: [font=Lucida Console]this.myLocationManager[/font] is initialized somewhere before :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby inter » Sat Apr 05, 2008 2:00 pm

Thank you

I have just done it . I added some lines in AndroidManifest.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.   <uses-permission android:name="android.Manifest.permission.ACCESS_GPS"/>
  2.  
  3.    <uses-permission android:name="android.Manifest.permission.ACCESS_LOCATION"/>
  4.  
  5.    <uses-permission android:name="android.Manifest.permission.ACCESS_ASSISTED_GPS"/>
  6.  
  7.    <uses-permission android:name="android.Manifest.permission.ACCESS_CELL_ID"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


It works .Thank you
inter
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 21, 2008 10:13 am

Top

Still getting the null ptr exception

Postby joydeep » Wed Apr 09, 2008 6:58 am

Hi plusminus,

I seem to be still getting the null ptr exception even after making inter's suggested changes to add the permissions to the AndroidManifest.xml, as well as your change to getting the "gps" location provider. Also this.myLocationManager is getting initialized when the activity is first created at the line:
this.myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

The null ptr exception is happening at the line:
LocationProvider provider = this.myLocationManager.getProvider("gps");

and neither "this" nor this.myLocationManager are null at that time, so it must be happening deep inside the method getProvider() and eclipse will not allow me to step into this method. Am I missing something?

Thanks,

--Joydeep
joydeep
Freshman
Freshman
 
Posts: 3
Joined: Wed Apr 09, 2008 6:49 am

more about the NullPointerException

Postby joydeep » Wed Apr 09, 2008 3:46 pm

Hi plusminus,

Here is some more data if it can provide any more clues to my NullPointerException. I added the following line before the problematic line:
providerStatus = this.myLocationManager.getProviderStatus("gps");
and I see that provider status is LocationProvider.OUT_OF_SERVICE.

I also used DDMS to look at my emulator /data/misc/location/gps/ directory and see that this exists and contains the files location, nmea and properties. The nmea file has coordinate info, and the properties file has the following data:
requiresNetwork false
requiresSatellite false
requiresCell false
hasMonetaryCost false
supportsAltitude true
supportsBearing true
supportsSpeed true
repeat true
accuracy 100
powerRequirement 1

Also, the location file has:
gps,1193789209,37.42238666666666666666,-122.096535,0,0,0

Can you think of what may be wrong with my gps setup and why I can't find my mock gps provider from my emulator? I tried both m5 r14 as well as r15. If you cannot think of anything, I may have to try with m3.

Thanks in advance for your help,

Regards,

--Joydeep
joydeep
Freshman
Freshman
 
Posts: 3
Joined: Wed Apr 09, 2008 6:49 am

Progress!!

Postby joydeep » Wed Apr 09, 2008 4:10 pm

OK, I found the problem, it turned out to be a typo in inter's previous post. The "Manifest" field should be removed from the permissions values in the previous post. I'm surprised there weren't more fundamental syntax errors reported and this got detected so late. Now I have the "distance not set (km)" issues, which I'll try to solve using previous posts' suggestions.

Regards,

--Joydeep
joydeep
Freshman
Freshman
 
Posts: 3
Joined: Wed Apr 09, 2008 6:49 am

Postby ca050306 » Mon May 19, 2008 3:43 pm

Hi,

I have still this null ptr exception even after making the suggested changes

- add the permissions to the AndroidManifest.xml
- change to getting the "gps" location provider.

Any help will be welcome

Best regards
CA
ca050306
Freshman
Freshman
 
Posts: 6
Joined: Sat May 17, 2008 3:31 pm

Postby ca050306 » Wed May 21, 2008 4:39 pm

Problem solved. thanks

ca050306 wrote:Hi,

I have still this null ptr exception even after making the suggested changes

- add the permissions to the AndroidManifest.xml
- change to getting the "gps" location provider.

Any help will be welcome

Best regards
CA
ca050306
Freshman
Freshman
 
Posts: 6
Joined: Sat May 17, 2008 3:31 pm

problem in running program

Postby manju » Thu Jun 12, 2008 6:04 am

Hi...

Am very new to this android platform.Now i have some errors in running this above program. Can anyone pls help in clearing my errors pls...
The error is in following lines:

menu.add(0, 0, getString(R.string.map_menu_zoom_in));
menu.add(0, 1, getString(R.string.map_menu_zoom_out));
menu.add(0, 2, getString(R.string.map_menu_toggle_street_satellite));
menu.add(0, 3, getString(R.string.map_menu_back_to_list));

The underlined is the exact location of errors...

Thanks
manju
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Jun 09, 2008 9:38 am
Location: banglore

Postby jeanlaurent » Mon Sep 01, 2008 8:11 pm

Hi guys!

Is someone have successfully compile the app on the new sdk?

thx
jeanlaurent
Freshman
Freshman
 
Posts: 3
Joined: Mon Sep 01, 2008 3:24 pm

Re: The Friend Finder - MapActivity using GPS - FULL SOURCE

Postby indiabolbol » Fri Sep 26, 2008 4:27 pm

Anybody has Friend Finder sample application working with
android-sdk-windows-1.0_r1?

I was able to change all the code to compile and deploy. But unable to launch the application. It crashes with some exception.

I am attaching the zip.
Attachments
FriendFinder.zip
(64.53 KiB) Downloaded 356 times
indiabolbol
Freshman
Freshman
 
Posts: 4
Joined: Fri Sep 26, 2008 4:16 pm

Postby Marchu » Sat Sep 27, 2008 7:18 pm

Hello,

It looks like the problem is with the returned cursor (c) for the contacts list.
In my case this cursor returns null, and throws the exeption.
Don't know if thats the exeption you mean..

I got this error in lots of 0.9 demo's, when i migrate them to 1.0.
Still haven't found a solution or reason for this.
(but busy reading the docs about this)

edit:
One main cause for throwing a error, is that the folowing is missing in the AndroidManifest.XML.
<uses-library android:name="com.google.android.maps" />
This line comes in the application tags.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <application android:icon="@drawable/icon">
  3.  
  4.     <uses-library android:name="com.google.android.maps" />
  5.  
  6.     ....
  7.  
  8.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


But after changing that, the errors are gone, but the rewritten code won'twork.
There is to mutch changed and set inactive (probaly for not throwing errors..)
If i got some time i will give it a shot to rewrite the code.

For the null cursor i have at least found a solution. Was a permission problem.
Marchu
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Sep 27, 2008 4:11 pm
Location: Netherlands

Top
PreviousNext

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests