Sorry sir my bad, im kinda confused and answered impulsively. here are more
details. I have i listview that has the names local hospitals in my country
and when i click an item it would display in the new activity the details
of the hosptipals including a map view with an overlay.
Here is my code, geocoder starts at line 48. and at line 87 seems to be my
problem, i tried removing || addresses.size == 0 and it is not displaying a
toast meaning my address is not null. thanks!
..........
1. String loc = hosname.getText().toString() + ",Philippines";
2. cd = new ConnectionDetector(getApplicationContext());
3. isInternetPresent = cd.isConnectingToInternet();
4. //Toast.makeText(this, loc, Toast.LENGTH_SHORT).show();
5.
6. if (haveNetworkConnection()) {
7. if (loc != null && !loc.equals("")) {
8. new GeocoderTask().execute(loc);
9. }
10.
11. }
12. else {
13. Toast.makeText(this, "Internet Connection is Required to
view this map", Toast.LENGTH_LONG).show();
14. }
15. }
16.
17.
18.
19.
20. private boolean haveNetworkConnection() {
21. //boolean haveConnectedWifi = false;
22. //boolean haveConnectedMobile = false;
23.
24. ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
25. NetworkInfo[] netInfo = cm.getAllNetworkInfo();
26. for (NetworkInfo ni : netInfo) {
27. if (ni.getTypeName().equalsIgnoreCase("WIFI"))
28. if (ni.isConnected())
29. return true;
30. if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
31. if (ni.isConnected())
32. return true;
33. }
34. return false;
35. }
36. @Override
37. protected boolean isRouteDisplayed() {
38. // TODO Auto-generated method stub
39. return false;
40. }
41.
42. // An AsyncTask class for accessing the GeoCoding Web Service
43. private class GeocoderTask extends AsyncTask<String, Void,
List<Address>>{
44.
45. @Override
46. protected List<Address> doInBackground(String... locationName) {
47. // Creating an instance of Geocoder class
48. Geocoder geocoder = new Geocoder(getBaseContext());
49. List<Address> addresses = null;
50.
51. try {
52. // Getting a maximum of 3 Address that matches the input text
53. addresses = geocoder.getFromLocationName(locationName[0], 3);
54. } catch (IOException e) {
55. e.printStackTrace();
56. }
57. return addresses;
58. }
59.
60.
61. @Override
62. protected void onPostExecute(List<Address> addresses) {
63.
64. // Getting Reference to MapView of the layout activity_main
65. MapView mapView = (MapView) findViewById(R.id.mv1);
66.
67. // Setting ZoomControls
68. mapView.setBuiltInZoomControls(true);
69.
70. // Getting MapController for the MapView
71. MapController mc = mapView.getController();
72. mc.setZoom(19);
73.
74. // Getting Drawable object corresponding to a resource image
75. Drawable drawable =
getResources().getDrawable(R.drawable.marker);
76.
77.
78. // Getting Overlays of the map
79. List<Overlay> overlays = mapView.getOverlays();
80.
81. // Creating an ItemizedOverlay
82. LocationOverlay locationOverlay = new
LocationOverlay(drawable,getBaseContext());
83.
84. // Clearing the overlays
85. overlays.clear();
86.
87. if(addresses==null || addresses.size()==0){
88. Toast.makeText(getBaseContext(), "No Location found",
Toast.LENGTH_SHORT).show();
89.
90. // Redraws the map to clear the overlays
91. mapView.invalidate();
92. }
93.
94. // Adding Markers on Google Map for each matching address
95. for(int i=0;i<addresses.size();i++){
96.
97. Address address = (Address) addresses.get(i);
98.
99. // Creating an instance of GeoPoint, to display in Google Map
100. GeoPoint p = new GeoPoint(
101. (int)(address.getLatitude()*1E6),
102. (int)(address.getLongitude()*1E6)
103. );
104.
105. String addressText = String.format("%s, %s",
106. address.getMaxAddressLineIndex() > 0 ?
address.getAddressLine(0) : "",
107. address.getCountryName());
108.
109.
110. // Creating an OverlayItem to mark the point
111. OverlayItem overlayItem = new OverlayItem(p,
"Location",addressText);
112.
113. // Adding the OverlayItem in the LocationOverlay
114. locationOverlay.addOverlay(overlayItem);
115.
116. // Adding locationOverlay to the overlay
117. overlays.add(locationOverlay);
118.
119. // Locate the first location
120. if(i==0)
121. mc.animateTo(p);
122. }
123.
124. // Redraws the map
125. mapView.invalidate();
126.
127. }
128. }
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en