• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Geocoding help

I have code that won't compile. There are no errors in the code. Can anybody help me. My code is posted below.

MapsActivity class:
Code:
package your.gas.namespace;

import java.io.*;
import java.util.*;

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 com.google.android.maps.MapView.LayoutParams;
 
import android.location.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.*;
 
public class MapsActivity extends MapActivity 
{    
    MapView mapView; 
    MapController mc;
    GeoPoint p;
 
    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.ic_launcher);            
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
            return true;
        }
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        mapView = (MapView) findViewById(R.id.mapView);
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
        View zoomView = mapView.getZoomControls(); 
 
        zoomLayout.addView(zoomView, 
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT)); 
        mapView.displayZoomControls(true);
 
        mc = mapView.getController();
        String coordinates[] = {    	
        		"32.079867,-81.095504",
            	"32.079952,-81.095848",
            	"32.079331,-81.093501",
            	"32.078901,-81.091718",
            	"32.080643,-81.094379",
            	"32.08055,-81.094302",
            	"32.080455,-81.096143",
            	"32.08057,-81.095271",
            	"32.080811,-81.096724",
            	"32.08122,-81.092358",
            	"32.080792,-81.09637",
            	"32.080098,-81.093557",
            	"32.079734,-81.088033",
            	"32.081077,-81.092056",
            	"32.076211,-81.098446",
            	"32.080632,-81.094282",
            	"32.08095,-81.091417",
            	"32.079999,-81.089091",
            	"32.081199,-81.089381",
            	"32.081407,-81.090391"};
            	double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);
 
        p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));
 
        mc.animateTo(p);
        mc.setZoom(17); 
        mapView.invalidate();
    }
 
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
   
		public boolean onTouchEvent(MotionEvent event, MapView mapView) 
        {   
            //---when user lifts his finger---
            if (event.getAction() == 1) {                
                GeoPoint p = mapView.getProjection().fromPixels(
                    (int) event.getX(),
                    (int) event.getY());
 
                Geocoder geoCoder = new Geocoder(
                    getBaseContext(), Locale.getDefault());
                try {
                    List<Address> addresses = geoCoder.getFromLocation(
                        p.getLatitudeE6()  / 1E6, 
                        p.getLongitudeE6() / 1E6, 1);
 
                    String add = "";
                    if (addresses.size() > 0) 
                    {
                        for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); 
                             i++)
                           add += addresses.get(0).getAddressLine(i) + "\n";
                    }
 
                    Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
                }
                catch (IOException e) {                
                    e.printStackTrace();
                }   
                return true;
            }
            else                
                return false;
        }

		
    }

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

     <com.google.android.maps.MapView 
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        />
 
    <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        /> 
 
</RelativeLayout>
 
If you are using eclipse did you try to clean the project ? I think on the menu item. Project: Clean and then select the project you would like to clean.

wubbzy
 
Looking at your code closer I see there is some logic errors here. You have an array of coordinates where lat and lng is separated by comma, but the way you assigned to lat and lng, you are using 2 different coordinates from the array ?

What you really want is
lat = Double.parseDouble(coordiantes[0].split(",")[0]);
lng = Double.parseDouble(coodinates[0].split(",")[1]);

Still this will only show one coordinate on the map not all of your coodinates.

The way you have it now, the program will throw an exception. (NumberFormatException ??)

wubbzy
 
What I want the code to do is select one location at a time and give directions to it based on the current location. How far is my code from this??
 
I think you are looking to do something like this

http://androidforums.com/android-ap...cation-aware-point-interest-deals-social.html

:)

Based on your code posted here, you got a long way to go. First look for sample code on using GPS to detect where you are. I think you want to use google as your friend for code sample.

When I started to code up the App above a year ago I started with no JAVA or Andriod knowlege. So it is not hard, just take some time to sink in.

Good luck.
 
Back
Top Bottom