Android 地图中的地理编码

发布于 2024-10-16 16:47:20 字数 4967 浏览 3 评论 0原文

嗨..我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2024-10-23 16:47:20

错误显示 ClassNotFoundException 您确定使用正确的类名并已在 manifest 中声明此类吗?

The errors say ClassNotFoundException are you sure you're using the correct class name and have declared this class in manifest ??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文