I have created a infowindow for a marker and trying to set the address of a particular location by tapping on it but its not doing anything. Where am I making mistake?
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker marker) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.info_window, null, false);
anchor_name = (TextView) view.findViewById(R.id.ancor_name);
anchor_address = (TextView) view.findViewById(R.id.address_a);
LatLng latlng = marker.getPosition();
AsyncTask<LatLng, Void, String> mytask = new AsyncTask<LatLng, Void, String>() {
#Override
protected String doInBackground(LatLng... params) {
return getParticularLocationAddress(params[0]);
}
#Override
protected void onPostExecute(String result) {
anchor_address.setText(result);
anchor_name.setText("Ravi");
}
};
mytask.execute(latlng);
//anchor_address.setText(getParticularLocationAddress(latlng));
return view;
}
});
getParticularLocationAddress method is given as
public String getParticularLocationAddress(LatLng latlng) {
double longitude = latlng.longitude;
double latitude = latlng.latitude;
String marker_address = null;
try {
if (longitude != 0) {
Geocoder geo = new Geocoder(this.getApplicationContext(), Locale.getDefault());
addresses = geo.getFromLocation(latitude, longitude, 1);
marker_address = addresses.get(0).getAddressLine(0) + ", "
+ addresses.get(0).getAddressLine(1);
} else {
marker_address = "Can't resolve";
}
} catch (Exception e) {
e.printStackTrace();
}
return marker_address;
}
Related
I am currently working with the google map. I already show the markers and the title and snippet of the marker.
Now my problem is when I click the info window it will be redirected to a new activity and get the data of the marker that was clicked. Here is my code:
public class FindApartment extends Fragment implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener,GoogleMap.OnInfoWindowClickListener {
public static final String ID = "id";
public static final String VERIFICATION = "verification";
private static final String TAG_APARTMENTNAME = "apartmentName";
private static final String TAG_CATEGORY = "Category";
private static final String TAG_PRICE = "price_month";
public static final String LAT = "latt";
public static final String LNG = "longt";
MarkerOptions markerOptions = new MarkerOptions();
CameraPosition cameraPosition;
LatLng center, latLng;
String verification, apartmentname, category, price, id;
GoogleMap mGoogleMap;
LocationRequest mLocationRequest;
GoogleApiClient mGoogleApiClient;
Location mLastLocation;
Marker mCurrLocationMarker;
MapView mapView;
String tag_json_obj = "json_obj_req";
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_find_apartment, container, false);
mapView = (MapView) rootView.findViewById(R.id.map1);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
mapView.onResume();
return rootView;
}
#Override
public void onPause() {
super.onPause();
//stop location updates when Activity is no longer active
if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
}
#Override
public void onLocationChanged(Location location) {
mLastLocation = location;
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions myMarker = new MarkerOptions();
myMarker.position(latLng);
myMarker.title("me");
myMarker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
mCurrLocationMarker = mGoogleMap.addMarker(myMarker);
//move map camera
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,17));
getMarkers();
}
#Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap=googleMap;
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mGoogleMap.setOnInfoWindowClickListener(this);
if(mGoogleMap!= null){
mGoogleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker marker) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.info_window, null);
TextView textName = (TextView) view.findViewById(R.id.textName);
TextView textViewPrice = (TextView) view.findViewById(R.id.textViewPrice);
TextView detail = (TextView)view.findViewById(R.id.detail);
LatLng ll = marker.getPosition();
textName.setText(marker.getSnippet());
textViewPrice.setText(marker.getTitle());
detail.setText("click to see full detail");
return view;
}
});
}
I'm using Android Volley and the array is on the Stringrequest. How can I get the data of the marker that was clicked on info window?
private void addMarker(LatLng latLng, String category, final String price, final String id) {
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(price);
markerOptions.snippet(category);
markerOption(verification, markerOptions);
mGoogleMap.addMarker(markerOptions);
}
public void onInfoWindowClick(Marker marker) {
id = marker.getId();
String snippet = marker.getSnippet();
Intent intent = new Intent(getActivity(), InfoWindowActivity.class);
startActivity(intent);
}
private void markerOption(String verification, MarkerOptions markerOptions) {
if(verification.contains("pending")) {
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
}
else {
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
}
}
private void getMarkers() {
String url = Server.URL2 + "markers.php";
final HashMap<String, String> apartmentID = new HashMap<String, String>();
StringRequest strReq = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.e("Response: ", response.toString());
try {
JSONObject jObj = new JSONObject(response);
String getObject = jObj.getString("apartments");
JSONArray jsonArray = new JSONArray(getObject);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
verification = jsonObject.getString(VERIFICATION);
apartmentname = jsonObject.getString(TAG_APARTMENTNAME);
category = jsonObject.getString(TAG_CATEGORY);
price = jsonObject.getString(TAG_PRICE);
id = jsonObject.getString("userID");
apartmentID.put(ID, id);
latLng = new LatLng(Double.parseDouble(jsonObject.getString(LAT)), Double.parseDouble(jsonObject.getString(LNG)));
// Adds a data marker to show to google map
addMarker(latLng, category, price, id);
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}
});
AppController.getInstance().addToRequestQueue(strReq, tag_json_obj);
}
Intent intent = new Intent(getActivity(), InfoWindowActivity.class);
intent.putExtra("snippet", snippet);
intent.putExtra("id", id)
... //put all your info here
startActivity(intent);
Access that data on next activity for example in onCreate or wherever you need it.
String snippet = getIntent().getStringExtra("snippet");
int id = getIntent().getIntExtra("id");
...//get all your info here
Is it what you were looking for? Question is not completely clear..
I am developing an android application which displays a map. When it loads, it displays some addresses and sets markers for them.
When I click on any marker it should display a value in a custom view. But the custom text which is received from a json parser, gets a null value. When I click on the marker again, it sets correct value.
When I click on second marker it display 1st marker value. When I click on 2nd marker again it displays correct value. This process continues
Here's my code:
private class GeocoderTask extends AsyncTask<String, Void, List<Address>>{
private Context mainContxt;
Geocoder geocoder;
public GeocoderTask(Context con){
mainContxt=con;
}
#Override
protected List<Address> doInBackground(String... locationName) {
Geocoder geocoder = new Geocoder(mainContxt);
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocationName(locationName[0],1);
} catch (IOException e) {
e.printStackTrace();
}
return addresses;
}
#Override
protected void onPostExecute(List<Address> addresses) {
for(int i=0;i<addresses.size();i++){
Address address = (Address) addresses.get(i);
latLng = new LatLng(address.getLatitude(), address.getLongitude());
String addressText = String.format("%s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getCountryName());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(addressText);
if(i==0) {
googleMap.animateCamera(CameraUpdateFactory.zoomBy(14),2000,null);
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
googleMap.addMarker(markerOptions);
}
googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker_address) {
location=marker_address.getTitle();
Toast.makeText(getApplicationContext(),location, Toast.LENGTH_LONG).show();
new LoadSingleProperty().execute();
//new LoadImage().execute();
return false;
}
});
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker arg0) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
View myContentView = getLayoutInflater().inflate(
R.layout.custom_marker, null);
tempnew_price=getPrice(temptotal_price+"" +email);
TextView tvTitle = ((TextView) myContentView
.findViewById(R.id.title));
// tvTitle.setText(location);
tvSnippet = ((TextView) myContentView
.findViewById(R.id.snippet));
ivProperty = ((ImageView) myContentView
.findViewById(R.id.image_property));
tvTitle.setText(tempcovered_area+ " "+tempnew_price+System.getProperty("line.separator")+templocation);
tvSnippet.setText("A "+ tempbedroom + " "+tempproperty_type);
// new LoadImage().execute();
ivProperty.setImageBitmap(bmp);
return myContentView;
}
});
googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker arg0) {
Intent intent = new Intent(getBaseContext(),
search_property_activity.class);
intent.putExtra("Email", email);
startActivity(intent);
}
});
}
}
this is my loadsingle class coding.....
class LoadSingleProperty extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivityMap.this);
pDialog.setMessage("Loading Location. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
if(location!=null && !location.equals("")){
params.add(new BasicNameValuePair("Location", location));
json= jsonParser.makeHttpRequest(url_loc_address, "GET", params);
}
Log.d("MyLocation: ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
address = json.getJSONArray(TAG_ALL_ADDRESS);
//for (int i = 0; i < address.length(); i++) {
JSONObject c = address.getJSONObject(0);
templocation = c.getString(TAG_LOCATION);
tempcovered_area=c.getString(TAG_COVERED_AREA);
temptotal_price=c.getString(TAG_Total_Price);
tempbedroom=c.getString(TAG_BEDROOM);
tempproperty_type=c.getString(TAG_PROPERTY_TYPE);
tempemail=c.getString(TAG_EMAIL);
//}
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
new GeocoderTask(MainActivityMap.this).execute(location);
}
}
Help me friends ...thx in advance
Create a constructor for LoadSingleProperty
class LoadSingleProperty extends AsyncTask<String, String, String> {
Marker mMarker;
public LoadSingleProperty(Marker marker){
mMarker = marker;
}
.
.
.
}
and pass your marker object to it.
new LoadSingleProperty(marker_address).execute();
Once parsing is done set your marker's title using setTitle() method for the marker
mMarker.setTitle(c.getString(TAG_PROPERTY_TYPE));
where you currently do this
tempproperty_type=c.getString(TAG_PROPERTY_TYPE);
Don't forget to refresh your info window once title is reset
How to force refresh contents of the markerInfoWindow
You may also want to show some sort of a loading icon till this time since you're performing a network request.
EDIT:
In case you're using a custom titleview, get a reference to InfoWindowAdapter object before setting as a adapter to googleMap
InfoWindowAdapter infoWindowAdapter = new InfoWindowAdapter() {...
Once parsing is complete, get info window view for mMarker object by calling
infoWindowAdapter.getInfoWindow(mMarker);
Find your textView from the view obtained above and set its text. Then refresh your info window by calling showInfoWindow() to update the info window.
Also please refer this link.
The info window that is drawn is not a live view. The view is rendered
as an image (using View.draw(Canvas)) at the time it is returned. This
means that any subsequent changes to the view will not be reflected by
the info window on the map. To update the info window later (for
example, after an image has loaded), call showInfoWindow()
private class GeocoderTask extends AsyncTask<String, Void, List<Address>> {
private Context mainContxt;
Geocoder geocoder;
public GeocoderTask(Context con) {
mainContxt = con;
}
#Override
protected List<Address> doInBackground(String... locationName) {
Geocoder geocoder = new Geocoder(mainContxt);
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocationName(locationName[0], 1);
} catch (IOException e) {
e.printStackTrace();
}
return addresses;
}
#Override
protected void onPostExecute(List<Address> addresses) {
for (int i = 0; i < addresses.size(); i++) {
Address address = (Address) addresses.get(i);
latLng = new LatLng(address.getLatitude(),
address.getLongitude());
String addressText = String.format(
"%s, %s",
address.getMaxAddressLineIndex() > 0 ? address
.getAddressLine(0) : "", address
.getCountryName());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(addressText);
if (i == 0) {
googleMap.animateCamera(CameraUpdateFactory.zoomBy(14),
2000, null);
googleMap.animateCamera(CameraUpdateFactory
.newLatLng(latLng));
}
googleMap.addMarker(markerOptions);
}
}
}
Then you write below code
googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker_address) {
location = marker_address.getTitle();
new LoadSingleProperty().execute();
return false;
}
});
Take another customeWindowAdapter or else use the present one only and set that in onPostExecute() method of 'LoadSingleProperty' AsyncTask..
This will solve that.
ping here you have any queries
I tried to use reverse geocoding with AsyncTask but but the parameters of latitude and longitude that passes through the method doInBackground() are not happening correctly. any idea?
public class SitesAdapter extends ArrayAdapter<StackSite> {
public static Double lat;
public static Double lng;
#Override
public View getView(int pos, View convertView, ViewGroup parent){
...
lat = -1.80;
lng = -80.20;
...
}
public void start(){
new GetAddressTask(mContext).execute(lat, lng);
}
public static class GetAddressTask extends AsyncTask<Double, Void, String> {
//mContext
#Override
protected String doInBackground(Double... params) {
Geocoder gc = new Geocoder(mContext, Locale.getDefault());
List<Address> list = null;
String city = "";
double latitude = params[0];
double longitude = params[1];
try {
list = gc.getFromLocation(lat, lng, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (list != null && list.size() > 0) {
Address address = list.get(0);
city = String.format("%s, %s", address.getAdminArea(), address.getCountryName());
}
return city;
}
#Override
protected void onPostExecute(String city) {
tituloTxt.setText(city);
}
}
}
error:
11-21 15:10:24.409: E/Trace(24502): error opening trace file: No such file or directory (2)
Well after so only had to do this to pass the coordinates. First add coordinate to constructor LatLng(double latitude, double longitude) and pass the parameters.
lat = -1.80;
lng = -80.20;
LatLng latlng = new LatLng(lat, lng);
new GetAddressTask(mContext).execute(lat, lng);
Then inside the doInbackground method get parameters.
public static class GetAddressTask extends AsyncTask<LatLng, Void, String> {
//mContext
#Override
protected String doInBackground(LatLng... params) {
Geocoder gc = new Geocoder(mContext, Locale.getDefault());
List<Address> list = null;
String city = "";
LatLng loc = params[0]; //Get all parameters: latitude and longitude
try {
list = gc.getFromLocation(loc.latitude, loc.longitude, 1); //get specific parameters
} catch (IOException e) {
e.printStackTrace();
}
if (list != null && list.size() > 0) {
Address address = list.get(0);
city = String.format("%s, %s", address.getAdminArea(), address.getCountryName());
return city;
}else{
return "City no found";
}
}
#Override
protected void onPostExecute(String city) {
tituloTxt.setText(city);
}
}
before calling execute method, u can just create a constructor ,in which you can initialize your class data members which can be further used in doInBackground(..).
Add two variables to your class and set them when you create async task, then use them in method. Simple.
public class GetAddressTask extends AsyncTask<String, Void, String> {
Context mContext;
float lat,lin;
public void setLat(int lat){...}
//rest of class
of course you can make everything static (fields and setters).
Edit.
If you are calling execute with some parameters, remember that your values have to be set before calling execute.
I am making android application using openweather API, I want to get my current location and parse it to the URL,
I wrote this code, but the code crashes :
public class MainActivity extends FragmentActivity implements LocationListener {
private TextView cityText;
private TextView condDescr;
private TextView temp;
private TextView press;
private TextView windSpeed;
private TextView windDeg;
private TextView unitTemp;
private TextView hum;
private ImageView imgView;
public double lat=0.0;
public double longi=0.0;
private static String forecastDaysNum = "3";
private ViewPager pager;
LocationManager manager;
LocationProvider provider;
Criteria criteria;
private Context context=null;
public String city="";
////////////////////////////
public String getAddress(double latitude, double longitude){
if (Geocoder.isPresent()) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(lat,longi,1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(addresses != null && addresses.size() > 0) {
Address first = addresses.get(0);
StringBuilder sb = new StringBuilder();
if(first.getMaxAddressLineIndex() > 0){
sb.append(first.getAddressLine(0) + ", ");
}
sb.append(first.getLocality() + ", ");
sb.append(first.getCountryName());
//return sb.toString();
city=sb.toString();
//return city;
//return city;
}}
return city;}
//////////////////////////
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//String city = "London, UK";
manager=(LocationManager) getSystemService(context.LOCATION_SERVICE);
criteria=new Criteria();
String provider=manager.getBestProvider(criteria, false);
android.location.Location loc=manager.getLastKnownLocation(provider);
//double
// lat=loc.getLatitude();
// double
// longi=loc.getLongitude();
city=getAddress(lat, longi);
String lang = "en";
cityText = (TextView) findViewById(R.id.cityText);
temp = (TextView) findViewById(R.id.temp);
unitTemp = (TextView) findViewById(R.id.unittemp);
unitTemp.setText("°C");
condDescr = (TextView) findViewById(R.id.skydesc);
pager = (ViewPager) findViewById(R.id.pager);
imgView = (ImageView) findViewById(R.id.condIcon);
/*
condDescr = (TextView) findViewById(R.id.condDescr);
hum = (TextView) findViewById(R.id.hum);
press = (TextView) findViewById(R.id.press);
windSpeed = (TextView) findViewById(R.id.windSpeed);
windDeg = (TextView) findViewById(R.id.windDeg);
*/
JSONWeatherTask task = new JSONWeatherTask();
task.execute(new String[]{city,lang});
JSONForecastWeatherTask task1 = new JSONForecastWeatherTask();
task1.execute(new String[]{city,lang, forecastDaysNum});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private class JSONWeatherTask extends AsyncTask<String, Void, Weather> {
#Override
protected Weather doInBackground(String... params) {
Weather weather = new Weather();
String data = ( (new WeatherHttpClient()).getWeatherData(params[0], params[1]));
try {
weather = JSONWeatherParser.getWeather(data);
System.out.println("Weather ["+weather+"]");
// Let's retrieve the icon
weather.iconData = ( (new WeatherHttpClient()).getImage(weather.currentCondition.getIcon()));
} catch (JSONException e) {
e.printStackTrace();
}
return weather;
}
#Override
protected void onPostExecute(Weather weather) {
super.onPostExecute(weather);
if (weather.iconData != null && weather.iconData.length > 0) {
Bitmap img = BitmapFactory.decodeByteArray(weather.iconData, 0, weather.iconData.length);
imgView.setImageBitmap(img);
}
cityText.setText(weather.location.getCity() + "," + weather.location.getCountry());
temp.setText("" + Math.round((weather.temperature.getTemp() - 275.15)));
condDescr.setText(weather.currentCondition.getCondition() + "(" + weather.currentCondition.getDescr() + ")");
/*
temp.setText("" + Math.round((weather.temperature.getTemp() - 275.15)) + "°C");
hum.setText("" + weather.currentCondition.getHumidity() + "%");
press.setText("" + weather.currentCondition.getPressure() + " hPa");
windSpeed.setText("" + weather.wind.getSpeed() + " mps");
windDeg.setText("" + weather.wind.getDeg() + "°");
*/
}
}
private class JSONForecastWeatherTask extends AsyncTask<String, Void, WeatherForecast> {
#Override
protected WeatherForecast doInBackground(String... params) {
String data = ( (new WeatherHttpClient()).getForecastWeatherData(params[0], params[1], params[2]));
WeatherForecast forecast = new WeatherForecast();
try {
forecast = JSONWeatherParser.getForecastWeather(data);
System.out.println("Weather ["+forecast+"]");
// Let's retrieve the icon
//weather.iconData = ( (new WeatherHttpClient()).getImage(weather.currentCondition.getIcon()));
} catch (JSONException e) {
e.printStackTrace();
}
return forecast;
}
#Override
protected void onPostExecute(WeatherForecast forecastWeather) {
super.onPostExecute(forecastWeather);
DailyForecastPageAdapter adapter = new DailyForecastPageAdapter(Integer.parseInt(forecastDaysNum), getSupportFragmentManager(), forecastWeather);
pager.setAdapter(adapter);
}
}
#Override
public void onLocationChanged(android.location.Location location) {
// TODO Auto-generated method stub
lat=location.getLatitude();
longi=location.getLongitude();
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
I am getting RunTimeException.
the logCat says Invalid Provider:Null
I want to add 100 markers wtih Lat and Long from Sql server 2014
My markers don't show on the map. I dont know what is the problem.
Please help me improve my code or show me the better way to do it
this is my code
public class Location {
private String latlong_ID, latlong_nome;
private Double latlong_Lat, latlong_Long;
public Location(String latlong_ID, String latlong_nome,Double latlong_Lat,Double latlong_Long) {
this.latlong_ID = latlong_ID;
this.latlong_nome = latlong_nome;
this.latlong_Lat = latlong_Lat;
this.latlong_Long = latlong_Long;
}
public String getLatlong_ID() {
return latlong_ID;
}
public void setLatlong_ID(String latlong_ID) {
this.latlong_ID = latlong_ID;
}
public String getLatlong_nome() {
return latlong_nome;
}
public void setLatlong_nome(String latlong_nome) {
this.latlong_nome = latlong_nome;
}
public Double getLatlong_Lat() {
return latlong_Lat;
}
public void setLatlong_Lat(Double latlong_Lat) {
this.latlong_Lat = latlong_Lat;
}
public Double getLatlong_Long() {
return latlong_Long;
}
public void setLatlong_Long(Double latlong_Long) {
this.latlong_Long = latlong_Long;
}
}
public class LocationLatLong extends AsyncTask<String, String, String> {
String z = "";
// List<Location> locationList = new ArrayList<Location>();
#Override
protected void onPostExecute(String s) {
for(int i = 0 ; i < location.size() ; i++ ) {
createMarker(location.get(i).getLatlong_Lat(),location.get(i).getLatlong_Long(),location.get(i).getLatlong_nome());
}
super.onPostExecute(s);
}
#Override
protected String doInBackground(String... params) {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = "Error in connection with SQL server";
} else {
String query = "select * from LojaLocation";
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String LatLongID = rs.getString("Id");
String LatLongnome = rs.getString("Nome");
String LatLongLat = rs.getString("Latitude");
String LatLongLong = rs.getString("Longitudi");
Double LatLong_Lat1 = Double.valueOf(LatLongLat);
Double LatLong_Long1 = Double.valueOf(LatLongLong);
Location p = new Location(LatLongID, LatLongnome, LatLong_Lat1,LatLong_Long1 );
location.add(p);
}
z = "Success";
}
} catch (Exception ex) {
z = "Error retrieving data from table";
}
return z;
}
protected void createMarker(Double latitude, Double longitude, String title) {
map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_map_marker)));
}
do this on Map object to add Marker
LatLng latLong = new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("You"));