View unanswered posts | View active topics It is currently 23 May 2019, 12:47

Reply to topic  [ 2 posts ] 
 Συγκεκριμένο icon στο marker ανά κατηγορία των places 
Author Message

Joined: 01 Feb 2013, 17:19
Posts: 5
Post Συγκεκριμένο icon στο marker ανά κατηγορία των places

φτιάχνω μια εφαρμογή που εμφανίζει τα nearby places στην τρέχουσα θέση ενός χρήστη (η οποία εντοπίζεται με GPS). Η εφαρμογή τώρα λειτουργεί ως εξής. Ο χρήστης μέσω ενός spinner επιλέγει κατηγορία places, πχ. cafes και εμφανίζονται τα POIs σε ακτίνα 3km. Θα ήθελα να έχω διαφορετικό εικονίδιο σε κάθε marker που αντιστοιχεί σε συγκεκριμένη κατηγορία (πχ. στα cafes, στα εστιατόρια κλπ). Καμία ιδέα; (Δοκίμασα με συνθήκη if..else...μέσα στο OnPostExecute αλλά τίποτα).


package com.example.mobiletourismapp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import android.animation.ValueAnimator;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;


public class MainActivity extends FragmentActivity implements LocationListener{
   GoogleMap mGoogleMap;   
   Spinner mSprPlaceType;   
   String[] mPlaceType=null;
   String[] mPlaceTypeName=null;
   double mLatitude=0;
   double mLongitude=0;

   HashMap<String, String> mMarkerPlaceLink = new HashMap<String, String>();
   private LatLng temp;

   protected void onCreate(Bundle savedInstanceState) {
      // Array of place types
      mPlaceType = getResources().getStringArray(R.array.place_type);
      // Array of place type names
      mPlaceTypeName = getResources().getStringArray(R.array.place_type_name);
      // Creating an array adapter with an array of Place types
      // to populate the spinner
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, mPlaceTypeName);
      // Getting reference to the Spinner
      mSprPlaceType = (Spinner) findViewById(;
      // Setting adapter on Spinner to set place types
      Button btnFind;
      // Getting reference to Find Button
      btnFind = ( Button ) findViewById(;
      // Getting Google Play availability status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

           int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);

        }else { // Google Play Services are available
          // Getting reference to the SupportMapFragment
          SupportMapFragment fragment = ( SupportMapFragment) getSupportFragmentManager().findFragmentById(;
          // Getting Google Map
          mGoogleMap = fragment.getMap();
          // Enabling MyLocation in Google Map
          // Getting LocationManager object from System Service LOCATION_SERVICE
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

            // Creating a criteria object to retrieve provider
            Criteria criteria = new Criteria();

            // Getting the name of the best provider
            String provider = locationManager.getBestProvider(criteria, true);

            // Getting Current Location From GPS
            Location location = locationManager.getLastKnownLocation(provider);


            locationManager.requestLocationUpdates(provider, 20000, 0, this);
            mGoogleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
            public void onInfoWindowClick(Marker marker) {
               if (marker.getSnippet().equals("Current location")){
                  Intent intent = new Intent(getBaseContext(), PlaceDetailsActivity.class);
                  String reference = mMarkerPlaceLink.get(marker.getId());
                  intent.putExtra("reference", reference);
                  startActivity(intent); // Starting the Place Details Activity
          // Setting click event lister for the find button
         btnFind.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {   
               int selectedPosition = mSprPlaceType.getSelectedItemPosition();
               String type = mPlaceType[selectedPosition];
               StringBuilder sb = new StringBuilder("");
               // Creating a new non-ui thread task to download Google place json data
                 PlacesTask placesTask = new PlacesTask();                              
               // Invokes the "doInBackground()" method of the class PlaceTask
   /** A method to download json data from url */
    private String downloadUrl(String strUrl) throws IOException{
        String data = "";
        InputStream iStream = null;
        HttpURLConnection urlConnection = null;
                URL url = new URL(strUrl);               

                // Creating an http connection to communicate with url
                urlConnection = (HttpURLConnection) url.openConnection();               

                // Connecting to url

                // Reading data from url
                iStream = urlConnection.getInputStream();

                BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

                StringBuffer sb  = new StringBuffer();

                String line = "";
                while( ( line = br.readLine())  != null){

                data = sb.toString();


        }catch(Exception e){
                Log.d("Exception while downloading url", e.toString());

        return data;

   /** A class, to download Google Places */
   private class PlacesTask extends AsyncTask<String, Integer, String>{

      String data = null;
      // Invoked by execute() method of this object
      protected String doInBackground(String... url) {
            data = downloadUrl(url[0]);
         }catch(Exception e){
             Log.d("Background Task",e.toString());
         return data;
      // Executed after the complete execution of doInBackground() method
      protected void onPostExecute(String result){         
         ParserTask parserTask = new ParserTask();
         // Start parsing the Google places in JSON format
         // Invokes the "doInBackground()" method of the class ParseTask
   /** A class to parse the Google Places in JSON format */
   private class ParserTask extends AsyncTask<String, Integer, List<HashMap<String,String>>>{

      JSONObject jObject;
      private Location location;
      // Invoked by execute() method of this object
      protected List<HashMap<String,String>> doInBackground(String... jsonData) {
         List<HashMap<String, String>> places = null;         
         PlaceJSONParser placeJsonParser = new PlaceJSONParser();
              jObject = new JSONObject(jsonData[0]);
               /** Getting the parsed data as a List construct */
               places = placeJsonParser.parse(jObject);
           }catch(Exception e){
           return places;
      // Executed after the complete execution of doInBackground() method
      protected void onPostExecute(List<HashMap<String,String>> list){         
         // Clears all the existing markers
      mGoogleMap.addMarker (new MarkerOptions()
      .title ("You are here")
      .snippet("Current location")
         for(int i=0;i<list.size();i++){
            // Creating a marker
               MarkerOptions markerOptions = new MarkerOptions()
               // Getting a place from the places list
               HashMap<String, String> hmPlace = list.get(i);
               // Getting latitude of the place
               double lat = Double.parseDouble(hmPlace.get("lat"));              
               // Getting longitude of the place
               double lng = Double.parseDouble(hmPlace.get("lng"));
               // Getting name
               String name = hmPlace.get("place_name");
               // Getting vicinity
               String vicinity = hmPlace.get("vicinity");
               LatLng latLng = new LatLng(lat, lng);
               // Setting the position for the marker
               // Setting the title for the marker.
               //This will be displayed on taping the marker
               markerOptions.title(name + " : " + vicinity);   
               markerOptions.snippet("Click here for more info...");
               // Placing a marker on the touched position
               Marker m = mGoogleMap.addMarker(markerOptions);
               // Linking Marker id and place reference
               mMarkerPlaceLink.put(m.getId(), hmPlace.get("reference"));   

   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(, menu);
      return true;

   public void onLocationChanged(Location location) {
      mLatitude = location.getLatitude();
      mLongitude = location.getLongitude();
      LatLng latLng = new LatLng(mLatitude, mLongitude);
        mGoogleMap.addMarker (new MarkerOptions()
      .title ("You are here")
      .snippet("Current location")
      mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); // Showing current location in map   

   public void onProviderDisabled(String provider) {
      // TODO Auto-generated method stub

   public void onProviderEnabled(String provider) {
      // TODO Auto-generated method stub

   public void onStatusChanged(String provider, int status, Bundle extras) {
      // TODO Auto-generated method stub      

12 Jul 2014, 12:52

Joined: 09 Aug 2012, 13:03
Posts: 17
Post Re: Συγκεκριμένο icon στο marker ανά κατηγορία των places
Τελικά το έλυσες το πρόβλημα;

04 Oct 2014, 13:15
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 30 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.