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 7872739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:17:59+00:00 2026-06-03T02:17:59+00:00

I’m new to android programming, what I want to do is get location from

  • 0

I’m new to android programming, what I want to do is get location from two EditText source and destination and mark them on the map below, I am able to mark one marker on the map from a EditText on click of a button:

Here is my XML:

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



            <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

        <EditText
            android:id="@+id/location" 
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content" 
            android:hint="Type Your Address here"
            android:layout_weight="20"
             >
        </EditText>

        <Button
            android:id="@+id/geocodeBtn" 
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content" 
            android:text="Search"
            android:layout_weight="80"
               />
    </LinearLayout>

        <TextView 
            android:id="@+id/position" 
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content" 
            android:text="Latitude/Longitude..." /> 

                <com.google.android.maps.MapView  
        android:id="@+id/geoMap" android:layout_width="fill_parent"  
        android:layout_height="fill_parent" android:clickable="true"  
        android:apiKey="0I0jOn_3OgbSahP7YkXmjc3d6fn2Rwrdepi0noQ" />

        </LinearLayout>

This is the class code:

package bijoy.happy;

import java.util.List;

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

//import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SearchByAddressActivity extends MapActivity {
    MapView mapView;
    Geocoder geocoder;
    GeoPoint p,qt,pt;

    class MapOverlay extends com.google.android.maps.Overlay
{
    @Override
    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(
            getResources(), R.drawable.pin);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
        return true;
    }
}//end of class


    @Override 
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.geoMap);   
    mapView.setBuiltInZoomControls(true);   
    mapView.setClickable(true);   


    // map starting point   
    int lat = (int) (51.678383 * 1000000);   
    int lng = (int) (19.334822 * 1000000);   
    pt = new GeoPoint(lat, lng); 


    mapView.getController().setZoom(8);   

    mapView.getController().setCenter(pt);  

    Button geoBtn = (Button) findViewById(R.id.geocodeBtn);   

    geocoder = new Geocoder(this);     


    geoBtn.setOnClickListener(new OnClickListener() {   

        public void onClick(View v) {   
            try {   
                EditText locale = (EditText) findViewById(R.id.location);   
                String locationName = locale.getText().toString();   

                List<Address> addressList = geocoder.getFromLocationName(   
                        locationName, 5);   
                if (addressList != null && addressList.size() > 0) {   
                    int lat = (int) (addressList.get(0).getLatitude() * 1e6);   
                    int lng = (int) (addressList.get(0).getLongitude() * 1e6);   

                    TextView pozycja = (TextView) findViewById(R.id.position);   
                    pozycja.setText("lat: "  
                            + addressList.get(0).getLatitude() + " lng: "  
                            + addressList.get(0).getLongitude());   

                    p = new GeoPoint(lat, lng);   
                    mapView.getController().setZoom(18);   
                    mapView.getController().setCenter(p);   

                    //---Add a location marker---
                    MapOverlay mapOverlay = new MapOverlay();
                    List<Overlay> listOfOverlays = mapView.getOverlays();
                    listOfOverlays.clear();
                    listOfOverlays.add(mapOverlay); 


                    mapView.invalidate();

                }   
            } catch (Exception e) {   
                e.printStackTrace();   
            }   
        }   
    });   

}


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

XML code will have 1 more EditText and a button to search. Please help.!

  • 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-03T02:18:00+00:00Added an answer on June 3, 2026 at 2:18 am

    The following link might be able to help you:

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.