2016-10-19 2 views
-1

Пожалуйста, помогите мне, я создал класс newReclamation, в котором мы можем добавить название, название, должность, название и должность, с MapView. Как я могу добавить MapView и пометить свое положение вручную с помощью Marker, а затем сохранить (Lang, Lat) в базе данных mysql.Добавить MapView в мою компанию

PS: теперь я сохраняю только название, тип и описание, и оно работает. Пожалуйста, помогите мне.

public class NewReclamationActivity extends Activity implements OnItemSelectedListener { 

    // Progress Dialog 
    private ProgressDialog pDialog; 
    private SQLiteHandler db; 

    JSONParser jsonParser = new JSONParser(); 
    EditText inputName; 
    EditText inputDesc; 
    Spinner spinner; 



    // LogCat tag 
    private static final String TAG = NewReclamationActivity.class.getSimpleName(); 
    // JSON Node names 
    private static final String TAG_SUCCESS = "success"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.add_reclamation); 

     spinner = (Spinner) findViewById(R.id.spinner); 
     spinner.setOnItemSelectedListener(this); 
// Create an ArrayAdapter using the string array and a default spinner layout 
     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, 
       R.array.type_array, android.R.layout.simple_spinner_item); 
// Specify the layout to use when the list of choices appears 
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
// Apply the adapter to the spinner 
     spinner.setAdapter(adapter); 

     // Edit Text 
     inputName = (EditText) findViewById(R.id.inputName); 
     inputDesc = (EditText) findViewById(R.id.inputDesc); 

     // SqLite database handler 
     db = new SQLiteHandler(getApplicationContext()); 



     // Create button 
     Button btnCreateReclamation = (Button) findViewById(R.id.btnCreateReclamation); 

     // button click event 
     btnCreateReclamation.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View view) { 
       // creating new reclamation in background thread 
       new CreateNewReclamation().execute(); 
      } 
     }); 

    } 

    public void onItemSelected(AdapterView<?> parent, View view, 
           int pos, long id) { 
     // An item was selected. You can retrieve the selected item using 
     // parent.getItemAtPosition(pos) 
    } 

    public void onNothingSelected(AdapterView<?> parent) { 
     // Another interface callback 
    } 


    /** 
    * Background Async Task to Create new reclamation 
    * */ 
    class CreateNewReclamation extends AsyncTask<String, String, String> { 

     /** 
     * Before starting background thread Show Progress Dialog 
     * */ 
     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pDialog = new ProgressDialog(NewReclamationActivity.this); 
      pDialog.setMessage("Creating Reclamation.."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(true); 
      pDialog.show(); 

     } 




     /** 
     * Creating reclamation 
     * */ 

     // Fetching user details from SQLite 
     HashMap<String, String> user = db.getUserDetails(); 
     String user_id=user.get("uid"); 


     String name = inputName.getText().toString(); 
     String type = spinner.getSelectedItem().toString(); 
     String description = inputDesc.getText().toString(); 


     protected String doInBackground(String... args) { 


      // Building Parameters 
      List<NameValuePair> params = new ArrayList<NameValuePair>(); 
      params.add(new BasicNameValuePair("name", name)); 
      params.add(new BasicNameValuePair("type", type)); 
      params.add(new BasicNameValuePair("description", description)); 
      params.add(new BasicNameValuePair("user_id",user_id)); 

      // getting JSON Object 
      // Note that create product url accepts POST method 
      JSONObject json = jsonParser.makeHttpRequest(AppConfig.url_create_reclamation, 
        "POST", params); 

      // check log cat fro response 
      Log.d("Create Response", json.toString()); 

      // check for success tag 
      try { 
       int success = json.getInt(TAG_SUCCESS); 

       if (success == 1) { 
        // successfully created reclamation 
        Intent i = new Intent(getApplicationContext(), MainActivity.class); 
        startActivity(i); 

        // closing this screen 
        finish(); 
       } else { 
        // failed to create reclamation 
       } 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 

      return null; 
     } 

     /** 
     * After completing background task Dismiss the progress dialog 
     * **/ 
     protected void onPostExecute(String file_url) { 
      // dismiss the dialog once done 
      pDialog.dismiss(); 
     } 

    } 

Я хочу добавить вакансию, используя google map. Любые идеи, пожалуйста?

+0

Мы не сможем помочь вам, пока вы не поделитесь с нами кодом –

+0

Я отредактировал свою публикацию, вы можете найти мой код сейчас. я хочу добавить позицию с помощью карт Google и сохранить ее в базе данных. – salma

+0

. Начните с этого момента: https://developers.google.com/maps/documentation/android-api/start, потому что вам нужно реализовать карты Google, прежде чем вы сможете получить позиция от пользователя. –

ответ

1

Google предоставил действительно опрятное руководство для разработчиков, чтобы начать работу с API Карт для Android.

Взгляните на here для создания требуемого ключа API.

Не забудьте получить ключ API или он не будет работать

Вот XML для фрагмента на карте

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/map" 
tools:context=".MapsActivity" 
android:name="com.google.android.gms.maps.SupportMapFragment" /> 

и вот новичок сниппет для получения начал

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     // Add a marker in Sydney, Australia, and move the camera. 
     LatLng sydney = new LatLng(-34, 151); 
     mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
    } 
} 

Надеется, что это помогает

+0

@salma, удалось ли решить вашу проблему? – HenriqueMS

Смежные вопросы