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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:53:47+00:00 2026-06-03T09:53:47+00:00

I want to get the latitude and longitude positions from the Geo Coding API.

  • 0

I want to get the latitude and longitude positions from the Geo Coding API. I wrote the following code for that.

package com.appulento.mapsexample.pack;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.mapsinfo.pack.DBAdapter;

public class MapsMianClass extends MapActivity {

   private MapController   mapController;
    private LocationManager locationManager;
    private  MapView mapView;
    List<Overlay> listOfOverlays ;
    private List mapOverlays;
    private Projection projection;
    private Geocoder geoCoder;
    private MapController mc;
    private GeoPoint gP;
    private DBAdapter db;

   /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       //here i am giving the Maps Geo coding API   URL    

        Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false"));
        startActivity(intent);
        //starting the Intent
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    //default method of maps Activity.
    }         
}

Is it correct? How can I incorporate JSON in the above code for getting latitude and longitude values from the URL?

  • 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-03T09:53:49+00:00Added an answer on June 3, 2026 at 9:53 am

    Try this Code

    import android.app.Activity;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONArray;
    import org.json.JSONObject;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URI;
    
    public class MyActivity extends Activity {
        /**
         * Called when the activity is first created.
         */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
    
            AsyncTask<String, Void, Void> stringVoidVoidAsyncTask = new AsyncTask<String, Void, Void>() {
    
                BufferedReader in;
    
                @Override
                protected Void doInBackground(String... strings) {
    
                    String url = "";
                    if (strings.length > 0) {
                        url = strings[0];
                    } else {
                        return null;
                    }
                    try {
                        HttpClient httpClient = new DefaultHttpClient();// Client
                        HttpGet getRequest = new HttpGet();
    
                        getRequest.setURI(new URI(url));
                        HttpResponse response = httpClient.execute(getRequest);
    
    
                        in = new BufferedReader
                                (new InputStreamReader(response.getEntity().getContent()));
                        StringBuffer sb = new StringBuffer("");
                        String line = "";
                        String NL = System.getProperty("line.separator");
                        while ((line = in.readLine()) != null) {
                            sb.append(line + NL);
                        }
                        in.close();
                        String page = sb.toString();
                        JSONObject jsonObject = new JSONObject(page);
                        JSONArray jsonArray = (JSONArray) jsonObject.get("results");
                        if (jsonArray.length() > 0) {
                            jsonObject = (JSONObject) jsonArray.get(0);
                            jsonObject = (JSONObject) jsonObject.get("geometry");
                            JSONObject location = (JSONObject) jsonObject.get("location");
                            Double lat = (Double) location.get("lat");
                            Double lng = (Double) location.get("lng");
                            System.out.println("lat - " + lat + " , lon - " + lng);
                        }
                        System.out.println(page);
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (in != null) {
                            try {
                                in.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    return null; 
                }
            };
            stringVoidVoidAsyncTask.execute("http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true");
        }
    }
    

    And do add permission in AndroidManifest for Internet

    <uses-permission android:name="android.permission.INTERNET"/>
    

    And for next time do homework before asking question do googleing first. Hope this help you.

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

Sidebar

Related Questions

I want to get zip code from users current location(Latitude, Longitude), I had used
I want to get following values from Latitude and Longitude in android Street Address
I want to get the latitude and longitude from the result object returned by
I want to get latitude and longitude from address in one of my asp.net
I just want to get latitude & longitude using the post code with Google
i want to build an app for windows mobile that can get GPS locations(longitude
I want to get the Distance between two latitude and longitude in meter /
I have a table with two columns: latitude and longitude. I want to get
I'm working on a tool that will find the closest latitude/longitude position from a
I'm working with SimpleGeo API and I need to get place's latitude/longitude by ZIP

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.