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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:50:27+00:00 2026-06-09T04:50:27+00:00

I’m a noob trying to develop a location based app with google places. I

  • 0

I’m a noob trying to develop a location based app with google places. I can add my current location the ovelay but i can’t figure out what i am doing wrong so I can add places api results to my overlay. My query is successful in my webbrowser, but not my app i get reQuest Deined . If anyone could help it would be greatly appreciated. Thank You in advance!

Main Activity:

package com.example.fdu;

public class FindDealer extends MapActivity implements LocationListener {
MapView finddealer;
long start;
long stop;
MyLocationOverlay compass;
MapController controller;
int x, y;
GeoPoint touchedPoint;
Drawable delta, zulu;
List<Overlay> overlayList;
LocationManager lm;
String towers;
int lat;
int lon;



@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.finddealer);
    finddealer = (MapView) findViewById(R.id.mvFindDealer);
    finddealer.setBuiltInZoomControls(true);

    Touchy tango = new Touchy();
    overlayList = finddealer.getOverlays();
    overlayList.add(tango);
    compass = new MyLocationOverlay(FindDealer.this, finddealer);
    overlayList.add(compass);
    controller = finddealer.getController();
    GeoPoint point = new GeoPoint(51643234, 7848593);//<--Germany

    controller.setZoom(12);
    finddealer.invalidate();//<--New

    delta = getResources().getDrawable(R.drawable.map_pin_48);
    zulu= getResources().getDrawable(R.drawable.ic_launcher);

    //placing pinpoint at location
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);      
    Criteria crit = new Criteria();
    towers = lm.getBestProvider(crit, false);
    Location location = lm.getLastKnownLocation(towers);
    if(location != null){
        lat = (int) (location.getLatitude()*1E6);
        lon = (int) (location.getLongitude()*1E6);          
        GeoPoint ourLocation = new GeoPoint(lat, lon);
        controller.animateTo(ourLocation);
        OverlayItem oscar = new OverlayItem(ourLocation, "What's Up", "Homie");
        CustomPinPoint custom = new CustomPinPoint(delta, FindDealer.this);
        custom.InsertPinpoint(oscar);
        overlayList.add(custom);    

        String googlelat = String.valueOf((int) (location.getLatitude()*1E6));
        String googlelon = String.valueOf((int) (location.getLongitude()*1E6));     
        String googleplacesapi = "https://maps.googleapis.com/maps/api/place/search/json?location=" + googlelat + "," + googlelon + "&radius=50000&type=store&keyword=gold&sensor=false&key=My Key Redacted";

        try {           
            JSONObject googleObject = StoresNearMe.getJSONfromURL(googleplacesapi);
            JSONArray parsedGoogle = googleObject.getJSONArray("results");
            if(parsedGoogle.equals(null) ){
                Toast.makeText(FindDealer.this, "Unable to locate tower", Toast.LENGTH_SHORT).show();
            }else{
            for (int i = 0; i < parsedGoogle.length(); i++) {
            JSONObject parsedlocales = parsedGoogle.getJSONObject(i);
            if (i == 0){
                JSONObject geometrylocation = parsedlocales.getJSONObject("geometry").getJSONObject("location");
                String lat0 = geometrylocation.getString("lat");
                String lng0 = geometrylocation.getString("lng");
                double overlaylat0 = Double.parseDouble(lat0);
                double overlaylng0 = Double.parseDouble(lng0);
                GeoPoint resultLocation0 = new GeoPoint((int) (overlaylat0), (int) (overlaylng0));                      
                OverlayItem whiskey = new OverlayItem(resultLocation0, "What's Up", "Homie");
                CustomPinPoint custom0 = new CustomPinPoint(zulu, FindDealer.this);
                custom0.InsertPinpoint(whiskey);
                overlayList.add(custom0);
                break;
            } 
            if (i == 1){
                JSONObject geometrylocation = parsedlocales.getJSONObject("geometry").getJSONObject("location");
                String lat1 = geometrylocation.getString("lat");
                String lng1 = geometrylocation.getString("lng");
                double overlaylat1 = Double.parseDouble(lat1);
                double overlaylng1 = Double.parseDouble(lng1);
                GeoPoint resultLocation1 = new GeoPoint((int) (overlaylat1),(int) (overlaylng1));                       
                OverlayItem foxtrot = new OverlayItem(resultLocation1, "What's Up", "Homie");
                CustomPinPoint custom1 = new CustomPinPoint(zulu, FindDealer.this);
                custom1.InsertPinpoint(foxtrot);
                overlayList.add(custom1);
                break;
            }
            if (i == 2){
                JSONObject geometrylocation = parsedlocales.getJSONObject("geometry").getJSONObject("location");
                String lat2 = geometrylocation.getString("lat");
                String lng2 = geometrylocation.getString("lng");
                double overlaylat2 = Double.parseDouble(lat2);
                double overlaylng2 = Double.parseDouble(lng2);
                GeoPoint resultLocation2 = new GeoPoint((int) (overlaylat2),(int) (overlaylng2));                       
                OverlayItem hotel = new OverlayItem(resultLocation2, "What's Up", "Homie");
                CustomPinPoint custom2 = new CustomPinPoint(zulu, FindDealer.this);
                custom2.InsertPinpoint(hotel);
                overlayList.add(custom2);
                break;
            }
            }
          }            
      } catch (JSONException e) {
         // Log.d("log_tag","JSON parsing error - Google Places Api:" + e.getMessage());
      }                     

    }else{
        Toast.makeText(FindDealer.this, "Couldn't get provider", Toast.LENGTH_SHORT).show();
    }

}



@Override
protected void onPause() {
    // TODO Auto-generated method stub
    compass.disableCompass();
    super.onPause();
    lm.removeUpdates(this);
    finish();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    compass.disableCompass();
    super.onResume();
    lm.requestLocationUpdates(towers, 500, 1, this);
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
class Touchy extends Overlay{
    public boolean onTouchEvent(MotionEvent echo, MapView mike){
        if(echo.getAction()==MotionEvent.ACTION_DOWN){
            start=echo.getEventTime();
            x = (int) echo.getX();
            y = (int) echo.getY();
            touchedPoint = finddealer.getProjection().fromPixels(x, y);
        }
        if(echo.getAction()==MotionEvent.ACTION_UP){
            stop=echo.getEventTime();
        }
        if (stop - start > 1500) {
            AlertDialog alert = new AlertDialog.Builder(FindDealer.this).create();
            alert.setTitle("Pick an Option");
            alert.setMessage("Hag");
            alert.setButton("place a pinpoint", new DialogInterface.OnClickListener() {


                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                    OverlayItem oscar = new OverlayItem(touchedPoint, "What's Up", "Homie");
                    CustomPinPoint custom = new CustomPinPoint(zulu, FindDealer.this);
                    custom.InsertPinpoint(oscar);
                    overlayList.add(custom);

                }
            });
            alert.setButton2("Get Address", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
                    try{
                        List<Address> address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() / 1E6 , touchedPoint.getLongitudeE6() / 1E6, 1);
                        if (address.size() > 0){
                            String display = "";
                            for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++ ){                                 
                                display += address.get(0).getAddressLine(i) + "\n";
                            }
                            Toast yankee = Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG);
                            yankee.show();
                        }
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }finally{

                    }
                }
            });
            alert.setButton3("Toggle View", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    if (finddealer.isSatellite()){
                        finddealer.setSatellite(false);
                        finddealer.setStreetView(true);
                    }else{
                        finddealer.setSatellite(true);
                        finddealer.setStreetView(false);
                    }
                }
            });
            alert.show();
            return true;
        }
        return false;

    }
}
@Override
public void onLocationChanged(Location l) {
    // TODO Auto-generated method stub
    lat = (int) (l.getLatitude()* 1E6);
    lon = (int) (l.getLongitude()* 1E6);
    GeoPoint ourLocation = new GeoPoint(lat, lon);
    OverlayItem oscar = new OverlayItem(ourLocation, "What's Up", "Homie");
    CustomPinPoint custom = new CustomPinPoint(delta, FindDealer.this);
    custom.InsertPinpoint(oscar);
    overlayList.add(custom);
}

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub
    Toast.makeText( getApplicationContext(),"Gps Disabled", Toast.LENGTH_SHORT ).show();//<--New

}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub
    Toast.makeText( getApplicationContext(),"Gps Enabled",  Toast.LENGTH_SHORT ).show();//<--New
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub
    Toast.makeText(FindDealer.this, "StatusChanged" +provider, Toast.LENGTH_SHORT).show();
}
}

Stores Near Me

public class StoresNearMe {

public static JSONObject getJSONfromURL(String url){
    InputStream is = null;
    String result = "";
    JSONObject googleObject = null;

    //http post
    try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

    }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
    }

  //convert response to string
    try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
    }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
    }

    try{

        googleObject = new JSONObject(result);            
    }catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
    }

    return googleObject;
}
}

CustomPinPoint Java

public class CustomPinPoint extends ItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();
private Context charlie;

public CustomPinPoint(Drawable defaultMarker) {
    super(boundCenter(defaultMarker));
    // TODO Auto-generated constructor stub
}

public CustomPinPoint(Drawable mike, Context context) {     
    // TODO Auto-generated constructor stub
    this(mike);
    charlie = context;
}

@Override
protected OverlayItem createItem(int i) {
    // TODO Auto-generated method stub
    return pinpoints.get(i);
}

@Override
public int size() {
    // TODO Auto-generated method stub
    return pinpoints.size();
}

public void InsertPinpoint(OverlayItem india){
    pinpoints.add(india);
    this.populate();
}

}
  • 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-09T04:50:28+00:00Added an answer on June 9, 2026 at 4:50 am

    In your CustomPinPoint constructor you wrote

    public CustomPinPoint(Drawable mike, Context context) {     
        // TODO Auto-generated constructor stub
        this(mike);
        charlie = context;
    }
    

    you’re calling this(mike) instead of super(mike)
    So you basically never calls the super constructor which won’t create the ItemizedOverlay

    Also, I don’t know if it matters, but comparing this tutorial http://about-android.blogspot.co.il/2010/03/steps-to-place-marker-in-map-overlay.html to your code,

    CustomPinPoint custom = new CustomPinPoint(delta, FindDealer.this);
    

    should be

    CustomPinPoint custom = new CustomPinPoint(delta, this);
    

    one last thing, you’re calling this.populate() in your public void InsertPinpoint(OverlayItem india){

    since you haven’t override it, it should be only populate to make sure you call super’s populate(). Don’t know if it makes a different though.


    EDIT:
    Well, after some playing with your code, I found a few things..
    First, your query returns no results. when I removed the keyword=gold from the URL, it started to give results back.

    I’m a bit confused with your coordinates, GeoPoint to Location and stuff, The first result, using your code was placed in the sea near Africa. I assume that’s not where your store is. however, that coordinates for it were 81,74 or something like that. hardly an exact coordinate. Maybe you should try multiplying it by 1E6 like you did before the for loop.

    But regarding your original question.
    After making the changes I told you before, it doesn’t work. but reverting back to your original code, it does. The problem was that you simply wasn’t getting any results with your original URL. once I changed the URL, it receives the places and draws the marker (though you need to tinker a bit with displaying it correctly)

    Hope that works for you too

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
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 trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.