Android 地图中的地理编码
嗨..我在 android 地图中进行地理编码。(即)获取地址作为用户的输入&使用标记找到该特定点。我该怎么做?
我的代码
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 文件是
<?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>
当我尝试运行此文件时,我得到了运行时错误......在 DDMS 中......我得到了......
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.lang.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)
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.lang.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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误显示
ClassNotFoundException
您确定使用正确的类名并已在manifest
中声明此类吗?The errors say
ClassNotFoundException
are you sure you're using the correct class name and have declared this class inmanifest
??