0

I try to do a map with seach address/find location and take gps coordinate/find location. I can make to work one by one but I couldn't work them together in one map. These are my google map functions :

Address Search

    // When the search form is submitted
    jQuery('.js-form-search').on('submit', function(){
        GMaps.geocode({
            address: jQuery('.js-search-address').val().trim(),
            callback: function ($results, $status) {
                if (($status === 'OK') && $results) {
                    var $latlng = $results[0].geometry.location;

                    $mapSearch.removeMarkers();
                    $mapSearch.addMarker({ lat: $latlng.lat(), lng: $latlng.lng(), title: 'Adres : '+jQuery('.js-search-address').val()});
                    $mapSearch.fitBounds($results[0].geometry.viewport);


                        document.getElementById("lat").value =  $latlng.lat();
                        document.getElementById("long").value = $latlng.lng();

                } else {
                    alert('Adres Bilgisi Bulunamadı ! ');
                }
            }
        });

        return false;
    });

GPS Location finder

// When the GPS button clicked
    jQuery('.js-form-gps').on('submit', function(){
        GMaps.geolocate({
            success: function(position) {
            $mapSearch.setCenter(position.coords.latitude, position.coords.longitude);
            $mapSearch.addMarker({
                lat: position.coords.latitude,
                lng: position.coords.longitude,
                animation: google.maps.Animation.DROP,
                title: 'GeoLocation',
                infoWindow: {
                    content: '<div class="text-success"><i class="fa fa-map-marker"></i> <strong>Your location!</strong></div>'
                }
            });
        },
        error: function(error) {
            alert('Geolocation failed: ' + error.message);
        },
        not_supported: function() {
            alert("Your browser does not support geolocation");
        },
        always: function() {
            // Message when geolocation succeed
        }
        });

        return false;
    });        
};

How can I entegrate two of them ?

Thanks,

duncan
  • 31,401
  • 13
  • 78
  • 99
Emin
  • 23
  • 5
  • what do you mean by entegrate two? you might want to look at the (nearby search)[https://developers.google.com/maps/documentation/javascript/places#place_search_requests] if you want to limit the search result. – kaho Aug 25 '15 at 00:45
  • @kaho a button with GPS icon and click to show GPS location, an address search and show address location – Emin Aug 25 '15 at 06:10

0 Answers0