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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:44:10+00:00 2026-06-16T22:44:10+00:00

I am trying to getting location or want to show location on map by

  • 0

I am trying to getting location or want to show location on map by passing location name.
I did one sample project which show current location on map. But i don’t understand how to pass name and search place on Google map.
Here is my code which may help you to understand my problem.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.setSatellite(true);
    mapController = mapView.getController();
    mapController.setZoom(14); // Zoom 1 is world view
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
        0, new GeoUpdateHandler());

    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);

    String value = "kasarwadi,pune";
    // Do something with value!


    Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());    
      try {
          List<Address> addresses = geoCoder.getFromLocationName(
              value, 5);
          String add = "";
          if (addresses.size() > 0) {
           GeoPoint   p = new GeoPoint(
                      (int) (addresses.get(0).getLatitude() * 1E6), 
                      (int) (addresses.get(0).getLongitude() * 1E6));
              mapController.animateTo(p);    
              mapView.invalidate();
          }    
      } catch (IOException e) {
          e.printStackTrace();
      }

    myLocationOverlay.runOnFirstFix(new Runnable() {
      public void run() {
        mapView.getController().animateTo(myLocationOverlay.getMyLocation());
      }
    });

    Drawable drawable = this.getResources().getDrawable(R.drawable.point);
    itemizedoverlay = new MyOverlays(this, drawable);
    createMarker();
  }

  @Override
  protected boolean isRouteDisplayed() {
    return false;
  }

  public class GeoUpdateHandler implements LocationListener {

    @Override
    public void onLocationChanged(Location location) {
         String value = "kasarwadi,pune";
         // Do something with value!


         Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());    
           try {
               List<Address> addresses = geoCoder.getFromLocationName(
                   value, 5);
               String add = "";
               if (addresses.size() > 0) {
                GeoPoint   p = new GeoPoint(
                           (int) (addresses.get(0).getLatitude() * 1E6), 
                           (int) (addresses.get(0).getLongitude() * 1E6));
                   mapController.animateTo(p);    
                   mapView.invalidate();
               }    
           } catch (IOException e) {
               e.printStackTrace();
           }


    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
  }

  private void createMarker() {
    GeoPoint p = mapView.getMapCenter();
    OverlayItem overlayitem = new OverlayItem(p, "", "");
    itemizedoverlay.addOverlay(overlayitem);
    if (itemizedoverlay.size() > 0) {
      mapView.getOverlays().add(itemizedoverlay);
    }
  }

  @Override
  protected void onResume() {
    super.onResume();
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.enableCompass();
  }

  @Override
  protected void onPause() {
    super.onPause();
    myLocationOverlay.disableMyLocation();
    myLocationOverlay.disableCompass();
  }

I also generate MD5 fingerprint and valid api key. but when i am trying to show it show only current location but i need to show location which name pass by me.
Please give me an reference or hint.
Thanks in advance.

  • 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-16T22:44:11+00:00Added an answer on June 16, 2026 at 10:44 pm

    I faced a similar problem on my emulator as well, may be it will end up working on device (not tested it on device yet!)so how i got around this is by using another raw api to translate address to geopoint …

    so, i would suggest don’t remove or change your current code (coz it looks fine to me and who knows may end up working on the device scenario), however call this method tryAlternative() in your catch (IOException) clause. I am writing down tryAlternative()

    private void tryAltesrnative(String address) {
    
        String strCompleteAddress = address.replaceAll(" ", "%20");
        String streetName = strCompleteAddress.substring(strCompleteAddress.indexOf(",")+1);
        String cityName = streetName.substring(streetName.indexOf(",")+1);
        String addressToToast = "";
    
    
        HttpGet httpGet = new HttpGet("http://maps.google." + "com/maps/api/geocode/json?address=" + address + "ka&sensor=false");
    
    
        HttpClient client = new DefaultHttpClient();
        HttpResponse response;
        StringBuilder stringBuilder = new StringBuilder();
    
        try {
            response = client.execute(httpGet);
            HttpEntity entity = response.getEntity();
            InputStream stream = entity.getContent();
            int b;
            while ((b = stream.read()) != -1) {
                stringBuilder.append((char) b);
            }
        } catch (ClientProtocolException e) {
        } catch (IOException e) {
        }
    
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject = new JSONObject(stringBuilder.toString());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    
    
        Double lon = new Double(0);
        Double lat = new Double(0);
    
        try {
    
            lon = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
                .getJSONObject("geometry").getJSONObject("location")
                .getDouble("lng");
    
            lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
                .getJSONObject("geometry").getJSONObject("location")
                .getDouble("lat");
    
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    
    
    
    
    
    
    
         point = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
    
         mapController.animateTo(point);
         mapController.setZoom(12);
    
         List<Overlay> mapOverlays = mapView.getOverlays();
         Drawable drawable = this.getResources().getDrawable(R.drawable.mark_green);
         AddItemizedOverlay itemizedOverlay = new AddItemizedOverlay(drawable, this);
    
         OverlayItem overlayitem = new OverlayItem(point, "Customer", addressToToast);
    
         itemizedOverlay.addOverlay(overlayitem);
         mapOverlays.add(itemizedOverlay);
         mapView.invalidate();
    
         Toast.makeText(this, "Lat: " + point.getLatitudeE6() +", Lon:  "+ point.getLongitudeE6() + "Address: " + addressToToast, Toast.LENGTH_LONG).show();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get current location of user using CLLocationCoordinate2D. I want the
I'm trying to make google mock but I'm only getting one library: gmock_main.a Why
I'm getting Permission Denied all the time when I'm trying to fetch my location
I'm trying to open a file with fopen, but I don't want a static
I am trying to do something really simple, but somehow not getting the direction.
I'm trying to add an alert dialog within a method, but I'm getting an
I'm trying to show an HTTP error document from a PHP page, but I
I am trying to get Altitude of my location in my application. But every
Getting TypeError: document.getElementById(free_shipping) is null This is what im trying --- I just want
I'm trying to implement jQuery masonry in my app, but not getting it to

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.