I want to make an android application for bicycle stations in Tehran. For that I need to show specific and static locations on the map like this:
I tried several libraries from Github but didn't work. I also added an extra location (double latitude1 = 35.747394; double longitude1 = 51.267577;)
but the location mark doesn't appear on the map.
I'd appreciate if anyone could help me.
This is my code:
MainActivity.java
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.MapFragment;
import com.playpersia.bicyclemap.R;
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 MapsActivity extends FragmentActivity {
double latitude1 = 35.747394;
double longitude1 = 51.267577;
// Google Map
private GoogleMap googleMap;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
Uri gmmIntentUri = Uri.parse("geo:35.694677, 51.394871");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //***Change Here***
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mapIntent);
finish();
}
try {
initilizeMap();
MarkerOptions markerOptions1 = new MarkerOptions().position(
new LatLng(latitude1, longitude1)).title("بوستان جوانمردان");
googleMap.addMarker(markerOptions1);
} catch (Exception e) {
e.printStackTrace();
}
}
@
Override
protected void onResume() {
super.onResume();
initilizeMap();
}
private void initilizeMap() {
if (googleMap == null) {
SupportMapFragment mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map));
if (googleMap != null) {
Toast.makeText(getApplicationContext(), "خطا", Toast.LENGTH_LONG).show();
}
}
}
}