geocoding in android map
HI..I doing geocoding in android map.(i.e)getting address as input from user & locate that particular point using marker.How could i do this?
My code
simpleGoogleMaps.java
public class simpleGoogleMaps extends MapActivity
{
Geocoder geocoder=null;
MapView mapView=null;
@Override
protected boolean isLocationDisplayed(){
return false;
}
@Override
protected boolean isRouteDisplayed(){
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView=(MapView)findViewById(R.id.map);
mapView.setBuiltInZoomControls(true);
Button geoBtn=(Button)findViewById(R.id.geocodeBtn);
geocoder=new Geocoder(this);
geoBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View srg0){
try{
EditText loc=(EditText)findViewById(R.id.location);
String locationName=loc.getText().toString();
List<Address>addressList=geocoder.getFromLocationName(locationName,5);
if(addressList!=null && addressList.size()>0)
{
int lat=(int)(addressList.get(0).getLatitude()*1000000);
int lng=(int)(addressList.get(0).getLongitude()*1000000);
GeoPoint pt=new GeoPoint(lat,lng);
mapView.getController().setZoom(15);
mapView.getController().setCenter(pt);
}
}catch(IOException e){
e.printStackTrace();
}
}});
}
}
XML file is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText android:layout_width="fill_parent"
android:id="@+id/location"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/geocodeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find"/>
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/map" android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="320px"
android:apiKey=
"0JfVbxbXShKp6h-xycpoR1hw_yawrKng5eUMX0g"/>
</RelativeLayout>
when i try to run this.,i got run time error....in DDMS..i got..
02-09 12:25:55.735: WARN/dalvikvm(360): threadid=3:
thread exiting with uncaught exception (group=0x4001aa28)
02-09 12:25:55.744: ERROR/AndroidRuntime(360):
Uncaught handler: thread main exiting due to uncaught exception
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
java.lang.RuntimeException: Unable to instantiate
activity ComponentInfo{com.make/com.make.simpleGoogleMaps}:
java.lang.ClassNotFoundException: com.make.simpleGoogleMaps
in loader dalvik.system.PathClassLoader@4376a9f8
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.app.ActivityThread.access$2100(ActivityThread.java:116)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.os.Looper.loop(Looper.java:123)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.app.ActivityThread.main(ActivityThread.java:4203)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at java.lang.reflect.Method.invokeNative(Native Method)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at java.lan开发者_StackOverflow社区g.reflect.Method.invoke(Method.java:521)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at dalvik.system.NativeStart.main(Native Method)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
Caused by: java.lang.ClassNotFoundException:
com.make.simpleGoogleMaps in loader dalvik.system.PathClassLoader@4376a9f8
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
02-09 12:25:55.774: ERROR/AndroidRuntime(360):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
The errors say ClassNotFoundException
are you sure you're using the correct class name and have declared this class in manifest
??
精彩评论