| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- package com.usai.apex;
- //
- //import com.google.android.gms.maps.GoogleMap;
- //import com.google.android.gms.maps.MapFragment;
- //import com.google.android.gms.maps.SupportMapFragment;
- //import com.google.android.gms.maps.model.LatLng;
- //import com.google.android.gms.maps.model.MarkerOptions;
- import com.google.android.gms.maps.GoogleMap;
- import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
- import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
- import com.google.android.gms.maps.CameraUpdateFactory;
- import com.google.android.gms.maps.MapFragment;
- import com.google.android.gms.maps.SupportMapFragment;
- import com.google.android.gms.maps.model.CameraPosition;
- import com.google.android.gms.maps.model.LatLng;
- import com.google.android.gms.maps.model.LatLngBounds;
- import com.google.android.gms.maps.model.Marker;
- import com.google.android.gms.maps.model.MarkerOptions;
- import com.usai.util.Network;
- import android.annotation.SuppressLint;
- import android.content.Intent;
- import android.os.Build;
- //import android.app.Fragment;
- //import android.app.FragmentManager;
- //import android.app.FragmentManager;
- //import android.app.Fragment;
- //import android.app.FragmentManager;
- //import android.app.FragmentManager;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentManager;
- //import android.support.v4.app.FragmentManager;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Toast;
- public class ServiceLocationFragment extends Fragment implements
- OnMarkerClickListener, OnInfoWindowClickListener
- {
- static final CameraPosition US =
- new CameraPosition.Builder().target(new LatLng(37.646374,
- -122.398847))
- .zoom(2.5f)
- .bearing(0)
- .tilt(0)
- .build();
- private SupportMapFragment fragment;
- private GoogleMap map;
- //
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- return inflater.inflate(R.layout.fragment_service_location, container,
- false);
- }
- @Override
- public void onActivityCreated(Bundle savedInstanceState)
- {
- super.onActivityCreated(savedInstanceState);
- FragmentManager fm = getChildFragmentManager();
- fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
- if (fragment == null)
- {
- fragment = new SupportMapFragment();// .newInstance();
- fm.beginTransaction().replace(R.id.map, fragment).commit();
- }
- }
- @Override
- public void onResume()
- {
- super.onResume();
- if (map == null)
- {
- map = fragment.getMap();
- map.addMarker(new MarkerOptions().position(new LatLng(37.646374,
- -122.398847)).title("Apex Maritime Co., Inc.").snippet("Click for more info."));
- }
- if(map!=null)
- setUpMap();
- }
- private void setUpMap()
- {
- // // Hide the zoom controls as the button panel will cover it.
- // map.getUiSettings().setZoomControlsEnabled(false);
- //
- // // Add lots of markers to the map.
- // addMarkersToMap();
- //
- // // Setting an info window adapter allows us to change the both the
- // contents and look of the
- // // info window.
- // map.setInfoWindowAdapter(new CustomInfoWindowAdapter());
- // Set listeners for marker events. See the bottom of this class for
- // their behavior.
- map.moveCamera(CameraUpdateFactory.newCameraPosition(US));
- map.setOnMarkerClickListener(this);
- map.setOnInfoWindowClickListener(this);
- // map.setOnMarkerDragListener(this);
- // Pan to see all markers in view.
- // Cannot zoom to bounds until the map has a size.
- // final View mapView = getChildFragmentManager().findFragmentById(
- // R.id.map).getView();
- // if (mapView.getViewTreeObserver().isAlive())
- // {
- // mapView.getViewTreeObserver().addOnGlobalLayoutListener(
- // new OnGlobalLayoutListener()
- // {
- // @SuppressWarnings("deprecation")
- // // We use the new method when supported
- // @SuppressLint("NewApi")
- // // We check which build version we are using.
- // @Override
- // public void onGlobalLayout()
- // {
- // LatLngBounds bounds = new LatLngBounds.Builder()
- // .include(PERTH).include(SYDNEY)
- // .include(ADELAIDE).include(BRISBANE)
- // .include(MELBOURNE).build();
- // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
- // {
- // mapView.getViewTreeObserver()
- // .removeGlobalOnLayoutListener(this);
- // }
- // else
- // {
- // mapView.getViewTreeObserver()
- // .removeOnGlobalLayoutListener(this);
- // }
- // map.moveCamera(CameraUpdateFactory.newLatLngBounds(
- // bounds, 50));
- // }
- // });
- // }
- }
- @Override
- public void onInfoWindowClick(Marker marker) {
- // Toast.makeText(getActivity(), "Click Info Window", Toast.LENGTH_SHORT).show();
- Intent intent = new Intent();
- intent.setClass(getActivity(), LocationDetailActivity.class);
- // intent.putExtra("user", user);
- // // intent.putExtra("password", password);
- // intent.putExtra("function_name", function_name);
- // intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
- startActivity(intent);
-
- }
- @Override
- public boolean onMarkerClick(Marker arg0)
- {
- // TODO Auto-generated method stub
- return false;
- }
- }
|