Geocoder doesn't work !!! Suggestions please...

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

Geocoder doesn't work !!! Suggestions please...

Postby ashwinthegrim » Tue Mar 31, 2009 6:33 pm

Hi All

I'm working on a project that takes in an address and gets the latitude and longitude of the address. I haven't done anything complicated yet. I just created the project and added one line

private Geocoder g = new Geocoder(this);

When I compile the code and execute it, I get the following error on the emulator, "The Application Testing Geocoder has stopped unexpectedly. Please try again."

I have also added the two lines to the AndroidManifest.xml as follows, within the <application> </application> tags.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

Can someone figure out what's wrong? Any help is greatly appreciated. Thank you.
ashwinthegrim
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:26 am

Top

Postby Yinten » Tue Mar 31, 2009 6:44 pm

The only permission you would need is:

<uses-permission android:name="android.permission.INTERNET" />


Is your "this" not an activity context?

public class GeoCoderTool
{

public static void GeoCodeTextMessage(String incomingAddress, Context mCtx)
{
Geocoder myCoder = new Geocoder(mCtx);

List<Address> addressList = null;

try
{
addressList = myCoder.getFromLocationName(incomingAddress, 1);
}
catch (IOException e)
{
e.printStackTrace();
}


if(addressList == null)
{
System.out.println("GEO CODER FAILED TO INITIALIZE");
}
else if(addressList.size() == 0)
{
System.out.println("GEO CODER FAILED TO RETURN RESULTS");
}
else
{
System.out.println("Latitude: " + addressList.get(0).getLatitude());
System.out.println("Longitude: " + addressList.get(0).getLongitude());
}
}

}
Yinten
Developer
Developer
 
Posts: 27
Joined: Tue Jan 20, 2009 7:27 pm

Postby Yinten » Tue Mar 31, 2009 6:47 pm

I put my permissions below the manifests tags above the application tags as well, not sure if that matters.
Yinten
Developer
Developer
 
Posts: 27
Joined: Tue Jan 20, 2009 7:27 pm

Postby ashwinthegrim » Tue Mar 31, 2009 7:06 pm

I'm declaring the Geocoder instance within the main class.. I'm including my whole code below.. Please check if something's wrong with it..

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package test.geo;
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.location.Geocoder;
  9.  
  10. import android.os.Bundle;
  11.  
  12.  
  13.  
  14. public class TestGeo extends Activity {
  15.  
  16.     /** Called when the activity is first created. */
  17.  
  18.     private Geocoder g = new Geocoder(this);
  19.  
  20.         @Override
  21.  
  22.     public void onCreate(Bundle savedInstanceState) {
  23.  
  24.         super.onCreate(savedInstanceState);
  25.  
  26.         setContentView(R.layout.main);
  27.  
  28.     }
  29.  
  30. }
  31.  
  32.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


As you can probably see, there is nothing here that can possible go wrong, since I'm only declaring an instance of Geocoder.
ashwinthegrim
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 26, 2008 4:26 am

Postby Yinten » Tue Mar 31, 2009 8:47 pm

package test.geo;

import android.app.Activity;
import android.location.Geocoder;
import android.os.Bundle;

public class TestGeo extends Activity {
/** Called when the activity is first created. */
private Geocoder g;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
g = new Geocoder(this);
}
}

You need to call super before you can use this.
Yinten
Developer
Developer
 
Posts: 27
Joined: Tue Jan 20, 2009 7:27 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest