displaying pt.s on map by reverse geocodng

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

displaying pt.s on map by reverse geocodng

Postby mala » Mon Mar 28, 2011 1:42 pm

Hi all,

My problem is that for my app I have to send an API which contains some parameters among which one is the area of the map view. For that I have to calculate my map view area.
For the location search functionality when some address is given to the search box by reverse Geocoding I am getting the lat lng for that address. Considering that lat lng as center pt. when I calculate the map view area every time it gives some different lat lng value for left-top and right-bottom co-ordinates. :?
here is my codding:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. try {
  2.                                         searchfor = searchText.getText().toString();
  3.                                         geoCoder = new Geocoder(getBaseContext(), Locale
  4.                                                         .getDefault());
  5.                                         List<Address> addresses = geoCoder.getFromLocationName(
  6.                                                         searchfor.toString(), 5);
  7.  
  8.                                         if (addresses.size() > 0) {
  9.                                                 point = new GeoPoint((int) (addresses.get(0)
  10.                                                                 .getLatitude() * 1E6), (int) (addresses.get(0)
  11.                                                                 .getLongitude() * 1E6));
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
[*]

and for calculation the map view area:

Syntax: [ Download ] [ Hide ]
  1. [*]     GeoPoint p = mapView.getProjection() 
  2.                             .fromPixels((int) mapView.getHeight(), 
  3.                                     (int) mapView.getWidth()); 
  4.                     Double lat = p.getLatitudeE6() / 1E6; 
  5.                     Double lng = p.getLongitudeE6() / 1E6; 
  6.                     GeoPoint q = mapView.getProjection().fromPixels((int) 0,(int) 0); 
  7.                     topCoordinate = "" + lng + "," + lat; 
  8.                     Double lat1 = q.getLatitudeE6() / 1E6; 
  9.                     Double lng1 = q.getLongitudeE6() / 1E6; 
  10.                     bottomCoOrdinate = "" + lng1 + "," + lat1; 
[*]



But I should get same value every time. Is not it! :oops:
Please help as soon as possible.


Thanks.
mala
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Jan 07, 2010 5:57 am
Location: bangalore

Top

Re: displaying pt.s on map by reverse geocodng

Postby adidmafioso » Sat Apr 02, 2011 7:56 am

Below is the code ,use it as it is.I think that would solve your prob ,if not ,feel free to ask.

geoPoint=mapView.getMapCenter();
Point p1 = new Point();
projection = mapView.getProjection();
projection.toPixels(geoPoint, p1);
Rect rectf = new Rect();
mapView.getLocalVisibleRect(rectf);
breadth=Integer.parseInt(String.valueOf(rectf.width()));
length=Integer.parseInt(String.valueOf(rectf.bottom));

GeoPoint ptopLeft = mapView.getProjection().fromPixels(p1.x-(rectf.width()/2),p1.y-(rectf.height()/2));
GeoPoint pbottomright = mapView.getProjection().fromPixels(p1.x+(rectf.width()/2),p1.y+(rectf.height()/2));

do reply,it makes me to ans more questions
adidmafioso
Developer
Developer
 
Posts: 33
Joined: Mon Sep 21, 2009 9:30 pm
Location: delhi

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 7 guests