請幫助我,我創建了一個類newReclamation
,我們可以在其中添加回收名稱,類型,描述和位置MapView
。我如何添加MapView
並用Marker
手動標記我的位置,然後在mysql數據庫中保存(Lang,Lat)。 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();
}
}
我想使用谷歌地圖添加位置。請有任何想法嗎?
我們不能幫助您,直到您與我們分享您的代碼 –
我編輯了我的出版物,您現在可以找到我的代碼。我想添加谷歌地圖的位置,並將其保存在數據庫中 – salma
您應該從這裏開始:https://developers.google.com/maps/documentation/android-api/start,因爲您必須先實施谷歌地圖,然後才能獲得來自用戶的位置。 –