Postingan lainnya
Marker maps android dari json
package com.example.my_pc.lokasi;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
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.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.geojson.GeoJsonLayer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleMap.OnMarkerClickListener {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
loadFile();
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-6.297269, 107.067625);
mMap.addMarker(new MarkerOptions().position(sydney).title("My Home"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
// Set a listener for marker click.
//mMap.setOnMarkerClickListener(this);
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(MapsActivity.this, "Klik", Toast.LENGTH_SHORT).show();
Log.d("Coba", "hasilnya");
for(int i = 0; i < 3; i++){
Toast.makeText(MapsActivity.this, "KE - "+i, Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(MapsActivity.this, "Tes", Toast.LENGTH_SHORT).show();
return false;
}
public String callfile(){
String json = null;
try {
InputStream is = getAssets().open("sekolah.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException e) {
// Should never happen!
throw new RuntimeException(e);
}/* catch (JSONException e) {
e.printStackTrace();
}*/
return json;
}
public void loadFile(){
//GeoJsonLayer layer = new GeoJsonLayer(getMap(), geoJsonData);
JSONObject obj = null;
try {
obj = new JSONObject(callfile());
JSONArray m_jArry = obj.getJSONArray("result");
for (int i = 0; i < m_jArry.length(); i++) {
JSONObject jo_inside = m_jArry.getJSONObject(i);
Toast.makeText(MapsActivity.this, jo_inside.getString("nama_sekolah"), Toast.LENGTH_SHORT).show();
Log.d("pesan", jo_inside.toString());
}
//Toast.makeText(MapsActivity.this, json, Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
saya ingin membuat marker dengan data dari json tpi knpa tidak muncul ya pas di parsenya., ada yang bisa bantu atau ada yang punya referensi? terimaksih
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban