Google Map Markers Ekleme Sorunu
Merhaba arkadaşlar,
Geliştirmekte olduğum bir projede harita üzerine marker ekleme problemi yaşıyorum. Web service de sıkıntım yok gayet düzgün bir şekilde çalışıyor.Android kısmında bir sorun olup olmadığından emin değilim.Harita üzerinde markerları bir türlü gösteremiyorum. Yazdığım kod aşağıda.Yardımcı olursanız sevinirim.
package com.example.kanbankasi;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
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 KanAriyorumMap extends FragmentActivity implements LocationListener {
SharedPreferences shared_preferences;
SharedPreferences share;
SharedPreferences.Editor shared_preferences_editor;
String test_string = "";
GoogleMap googleMap;
String lokasyonUrl;
private RequestQueue mRequestQueue;
double tempLat,tempLong;
RequestQueue kuyruk;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
shared_preferences = getApplicationContext().getSharedPreferences("appdata", 0);
test_string = shared_preferences.getString("kullaniciID", "Default");
share=getApplicationContext().getSharedPreferences("appdata", 0);
tempLat=0;
tempLong=0;
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else { // Google Play Services are available
// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
googleMap = fm.getMap();
// Enabling MyLocation Layer of Google Map
// googleMap.setMyLocationEnabled(true);
// googleMap.addMarker(new MarkerOptions()
// .position(new LatLng(41.2132055, 32.653043))
// .title("Hello world"));
// 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
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null){
onLocationChanged(location);
}
else{
Toast toast = Toast.makeText(getApplicationContext(),"Lütfen Tekrar Deneyiniz.", Toast.LENGTH_LONG);
toast.show();
}
locationManager.requestLocationUpdates(provider, 90000, 0, this);
}
}
@Override
public void onLocationChanged(Location location) {
TextView tvLocation = (TextView) findViewById(R.id.tv_location);
// Getting latitude of the current location
double latitude = location.getLatitude();
// Getting longitude of the current location
double longitude = location.getLongitude();
if(latitude!=tempLat | longitude!=tempLong){
googleMap.clear();
String link = getString(R.string.Url) + getString(R.string.Lokasyon) +"?" + "&long=" + longitude+ "&lang=" + latitude+"&kid="+test_string+ "&islem=findnearest";
Log.e("****", link.toString());
kuyruk = Volley.newRequestQueue(this);
JsonArrayRequest json = new JsonArrayRequest(link,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
for(int i = 0; i < response.length(); i++)
{
try {
JSONObject tmp = response.getJSONObject(i);
Log.i("usergecici2",tmp.getString("kid"));
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(tmp.getDouble("Lang"), tmp.getDouble("Long")))
.title(tmp.getString("kid") + tmp.getString("Kan_Grubu")));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
});
kuyruk.add(json);
}
tempLat=latitude;
tempLong=longitude;
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
mRequestQueue = Volley.newRequestQueue(this);
lokasyonUrl = getString(R.string.Url) + getString(R.string.Lokasyon) + "?"
+ "&long=" + longitude + "&lang=" +latitude +"&kid="+test_string+ "&islem=update";
@SuppressWarnings({ "rawtypes", "unchecked" })
StringRequest stringrequest = new StringRequest(Method.GET, lokasyonUrl,
new Response.Listener() {
public void onResponse(Object response) {
//finish();
}
}, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
}
});
mRequestQueue.add(stringrequest);
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// Setting latitude and longitude in the TextView tv_location
tvLocation.setText("Latitude:" + latitude + ", Longitude:"+ longitude );
}
@Override
public void onProviderDisabled(String provider) {
Toast a = Toast.makeText(getApplicationContext(),"Lütfen GPS'i açınız.", Toast.LENGTH_LONG);
a.show();
// 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
}
@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;
}
}