谷歌地图Android的搜索位置 [英] Google Map Android search location

查看:194
本文介绍了谷歌地图Android的搜索位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让按地址谷歌地图搜索

I'm Trying to make Google Map search by address

这是我的code为cari.java

here is my code for cari.java

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class cari extends com.google.android.maps.MapActivity {

       TextView error,pt;
       EditText cm;
       String i,returnStringLancar,stat;
       Geocoder geoCoder;
       GeoPoint p;
       MapController controller;
       MapView map;
        /** Called when the activity is first created. */

       @Override


        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.search);

            pt=(TextView)findViewById(R.id.peta);
            cm=(EditText)findViewById(R.id.cariMap);




       }

       public void clickHandler(View view){
           Intent a = null;
            switch (view.getId()){
            case R.id.show:
                geoCoder = new Geocoder(getApplicationContext(),
                        Locale.getDefault());
                List<Address> addresses;
                try {
                    addresses = geoCoder.getFromLocationName(cm.getText().toString(),5);
                if(addresses.size() > 0)
                {
                     p = new GeoPoint( (int) (addresses.get(0).getLatitude() * 1E6), 
                                      (int) (addresses.get(0).getLongitude() * 1E6));

                       controller.animateTo(p);
                       controller.setZoom(12);

                       MapOverlay mapOverlay = new MapOverlay();
                     List<Overlay> listOfOverlays = map.getOverlays();
                     listOfOverlays.clear();
                     listOfOverlays.add(mapOverlay);

                       map.invalidate();
                       cm.setText("");
                }
                else
                {
                        AlertDialog.Builder adb = new AlertDialog.Builder(cari.this);
                        adb.setTitle("Google Map");
                        adb.setMessage("Please Provide the Proper Place");
                        adb.setPositiveButton("Close",null);
                        adb.show();
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
                break;
       }
       }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}

这是我MapOverlay.java

and this is my MapOverlay.java

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.os.Bundle;

class MapOverlay extends com.google.android.maps.Overlay
{
    Context context;
    GeoPoint p;
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);                   

        //---translate the GeoPoint to screen pixels---
        Point screenPts = new Point();
        mapView.getProjection().toPixels(p, screenPts);

        //---add the marker---
        Bitmap bmp = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.icon);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-32, null);         
        return true;
    }
} 

这是我的布局XML:

search.xml

search.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android.autoText="true"
    />

<EditText 
android:text="Enter your address" 
android:id="@+id/address" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</EditText>
<Button 
android:text="Search" 
android:id="@+id/launchmap" 
android:layout_width="150px" 
android:layout_height="wrap_content">
</Button>

</LinearLayout>

我想,当我在EDITTEXT(例如:1152第一大街)写一个街道的名字是,和preSS的搜索按钮,它会显示一个谷歌地图上的位置(1152第一大街)

What I want is when I write name of one street in editText (example : 1152 1st Avenue) and press the search button, it will show the location (1152 1st Avenue) on a Google-map.

当我运行这个程序,,,它说:

when i run this program,,,it says

了java.lang.RuntimeException:无法实例活动ComponentInfo {udin.googlemap2 / udin.googlemap2.GoogleMap2}:

" java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{udin.googlemap2/udin.googlemap2.GoogleMap2}:"

抛出java.lang.ClassNotFoundException:udin.googlemap2.GoogleMap2装载机dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/udin.googlemap2-2.apk]\"

"java.lang.ClassNotFoundException: udin.googlemap2.GoogleMap2 in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/udin.googlemap2-2.apk]"

您能帮我吗?任何帮助将我AP preciate ....不管怎样,谢谢

can you help me?any help will i appreciate....Thanks anyway

推荐答案

检查是否&LT;使用库机器人:名字=com.google.android.maps/&GT; 在清单中给出。

Check whether<uses-library android:name="com.google.android.maps" /> is given in manifest..

这篇关于谷歌地图Android的搜索位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆