Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7712017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:31:23+00:00 2026-06-01T01:31:23+00:00

In my code I have one textbox and one button. Whatever place you type

  • 0

In my code I have one textbox and one button. Whatever place you type into the textbox, that place has to get searched from Google maps on clicking the button. And an icon has to be shown to the searched place.
In my code I am getting the map, but I am not able to search for the location. Please help.

  public class MapActivity extends com.google.android.maps.MapActivity implements
    OnClickListener {
/** Called when the activity is first created. */
MapView view;
Button search;
EditText location;
MapController controller;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    view = (MapView) findViewById(R.id.themap);
    location = (EditText) findViewById(R.id.editText1);
    search = (Button) findViewById(R.id.search);
    search.setOnClickListener(this);
    view.setBuiltInZoomControls(true);
}

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

public void onClick(View v) {
    // TODO Auto-generated method stub
    if (v == search) {
        Geocoder geo = new Geocoder(getApplicationContext(),
                Locale.getDefault());
        try {
            List<Address> addresses = geo.getFromLocationName(location
                    .getText().toString(), 5);
            if (addresses.size() > 0) {
                GeoPoint 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> lisOverlays = view.getOverlays();
                lisOverlays.clear();
                lisOverlays.add(mapOverlay);

            } else {
                AlertDialog.Builder adb = new AlertDialog.Builder(
                        MapActivity.this);
                adb.setTitle("Google Map");
                adb.setMessage("please provide proper place");
                adb.setPositiveButton("Close", null);
                adb.show();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
 }
  MapOverlay.java
   public class MapOverlay extends com.google.android.maps.Overlay
   {
Context context;
public boolean draw(Canvas canvas,MapView mapView,boolean shadow,long when)
{
    super.draw(canvas, mapView, shadow);
    Point screenPts = new Point();
    GeoPoint p = null;
    mapView.getProjection().toPixels(p, screenPts);
    Bitmap bitmap=BitmapFactory.decodeResource(context.getResources(),     R.drawable.ic_launcher);
    return true;

}

}

When I compile this, I am getting an error in the line: controller.animateTo(p);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:31:25+00:00Added an answer on June 1, 2026 at 1:31 am
    In oncreate() instantiate the Mapcontroller as below so that you will not get an error in animateTo method.
    
    controller= view.getController();
    
    also GeoPioint p =null; so replace the MAp overlay class with below
    
    
    MapOverlay.java
    
    public class MapOverlay extends com.google.android.maps.Overlay
    {
    GeoPoint p;
    Context context;
    public MyOverLay(Context context,GeoPoint p) // GeoPoint is a int. (6E) 
    { 
    this.p = p; 
    this.context = context;
    } 
    public boolean draw(Canvas canvas,MapView mapView,boolean shadow,long when)
    {
        super.draw(canvas, mapView, shadow);
        Point screenPts = new Point();
        mapView.getProjection().toPixels(p, screenPts);
        Bitmap bitmap=BitmapFactory.decodeResource(context.getResources(),     R.drawable.ic_launcher);
        return true;
    
    }
    

    then in your main code pass geopoint like below it will solve your problem….

    MapOverlay mapOverlay = new MapOverlay(getApplicationContext(),p);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that at one part will get executed a lot, and
I have a table that per row has some inputs and one edit button.
is there any development environments that allow you to have one code base that
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
In my webpage i have one textbox(hotel name) and a button. Suppose if i
I have a form with one textbox and one button. Here I need to
I have a form with one textbox and one button. Here I need to
I have a simple form with just one textbox and one submit button. The
I have a textbox and a button. On page load I select one column
In textbox I have to type string which will be searched in a table.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.