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

  • Home
  • SEARCH
  • 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 759089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:33:19+00:00 2026-05-14T15:33:19+00:00

package net.learn2develop.PopularAttractions; import java.io.IOException; import java.util.List; import java.util.Locale; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController;

  • 0

package net.learn2develop.PopularAttractions;

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

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

import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;

import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class PopularAttractions extends MapActivity {

private String[ ][ ] locations = {
        {"Chinatown Heritage Center","1.2836,103.84425"},
        {"Escape Theme Park","1.38104,103.936928"},
        {"G-Max Reverse Bungy","1.2906,103.845322"},
        {"Jurong BirdPark","1.32005,103.707153"},
        {"NEWater Visitor Center","1.33105,103.955311"},
        {"Red Dot Design Museum","1.277762,103.846225"},
        {"Singapore Botanic Garden","1.31471,103.815689"},
        {"Singapore Science Center","1.3249,103.740578"},
        {"Singapore Zoological Garden","1.40502,103.793449"},
        {"Snow City","1.32823,103.74263"},
        {"Sungei Buloh Wetland Reserver","1.445144,103.729595"},
        {"Super Ice World","1.300422,103.875348"},
    };

 Spinner spinnerView;
 MapView mapView;
 MapController mc;


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

    spinnerView = (Spinner) this.findViewById(R.id.spinner1);
    mapView = (MapView) findViewById(R.id.mapview1);
    mc = mapView.getController();

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_dropdown_item);

    for(int i = 0; i < locations.length; i++)
        adapter.add(locations[i][0]);


    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerView.setAdapter(adapter);
    spinnerView.setOnItemSelectedListener(selectListener);

    gotoSelected();
}



private OnItemSelectedListener selectListener = new OnItemSelectedListener() {

    public void onItemSelected(
            AdapterView<?>parent, View v, int position, long id)
    {
        gotoSelected();
    }

    public void onNothingSelected(AdapterView<?> arg0) {}

};


public void gotoSelected()
{

    int index = spinnerView.getSelectedItemPosition();
    String[] coordinates = locations[index][1].split(",");
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    Geocoder geocoder = new Geocoder(this, Locale.getDefault()); 
    try {
        List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
         Address ad = addresses.get(0); 
        String buff = new String();
    for(int i = 0; i <= ad.getMaxAddressLineIndex(); i++ ) { 
             buff += ad.getAddressLine(i);
     Toast.makeText(getBaseContext(), buff, Toast.LENGTH_SHORT).show();
  GeoPoint location = new GeoPoint (
        (int)(lat * 1E6),
        (int)(lng * 1E6));

            mc.animateTo(location);
            mc.setZoom(16);

      mapView.setStreetView(true);


     }
     for (Address a : addresses) { 
         Log.v("TAG", a.toString()); 
     } 


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

}

public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    MapController mc = mapView.getController(); 
    switch (keyCode) 
    {
        case KeyEvent.KEYCODE_2:
            mc.zoomIn();
            break;
        case KeyEvent.KEYCODE_1:
            mc.zoomOut();
            break;
    }
    return super.onKeyDown(keyCode, event);
}

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

}
  • 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-05-14T15:33:19+00:00Added an answer on May 14, 2026 at 3:33 pm

    You could try Geocoder: https://developer.android.com/reference/android/location/Geocoder.html

    for(int i = 0; i < locations.length; i++) {
    
            List<Address> list;
            Geocoder geo = new Geocoder(this); 
            try {
                    String[] latlong = locations[i][1].split(",");
                    list = geo.getFromLocation(Double.valueOf(latlong[0]), Double.valueOf(latlong[1]), 1); // the 1st result should be the best one
                    Address ad = list.get(0); // Position 0 is the most specific to the coordinates.
                    String buff = new String(); 
                    for(int i = 0; i <= ad.getMaxAddressLineIndex(); i++ ) {
                         buff += ad.getAddressLine(i); // for a good addres(with street name u should get getMaxAddressLineIndex() = 2
                         // HERE you would want to do something with buff to show or to store it
    
                     }
    
    
                    for (Address a : list) {
                        Log.v("TAG", a.toString());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
    

    Usually the first one in the list should be the one you are interested. For each Address you take the address with getAddressLine(int pos), normally you will get in position 0 the name of the street, in position 1 the zipcode + city and the next one the country. However, I haven’t made enough tests to be sure of this.

    To get the address you could use something like this:

    Address ad = list.get(0); // Position 0 is the most specific to the coordinates.
    String buff = new String(); 
    for(int i = 0; i <= ad.getMaxAddressLineIndex(); i++ ) {
        buff += ad.getAddressLine(i); // for a good addres(with street name u should get getMaxAddressLineIndex() = 2
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Could you just specify an empty constructor node in the… May 16, 2026 at 11:32 am
  • Editorial Team
    Editorial Team added an answer The main reason that extension method classed are not nested… May 16, 2026 at 11:32 am
  • Editorial Team
    Editorial Team added an answer If you don't interrupt the script it will, well, run… May 16, 2026 at 11:32 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm starting with Scala + Android (and using the sbt android plugin). I'm trying
The default ASP.NET web server that launches from within Visual Studio (Casini) is a
Is it possible to configure the ClickOnce installation so that it requires .Net Framework
I'm trying to deploy my ASP.NET MVC 2 Website for the first time on
I'm using VS2010 with the Web Deployment Projects to create a release package for
I'm looking for a PHP extension that allows me to connect, bind/listen, send, and
I'm trying to get started with Hibernate, and when executing my program I get
I use Eclipse with Websphere server . I need to add a session listener
I'm developing custom Agent for LotusNotes 8.5. I'd like to use iCal4j jar to
I'm interested in building a PC for a car that will boot off of

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.