Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with using Autocomplete and Map on same page #87

Closed
sschueller opened this issue Aug 30, 2014 · 7 comments
Closed

Problem with using Autocomplete and Map on same page #87

sschueller opened this issue Aug 30, 2014 · 7 comments
Labels

Comments

@sschueller
Copy link

Is there a way to have both a map with markers etc as well as an autocomplete places form on the same page? I can get either one to work but not together.

I get "Uncaught TypeError: undefined is not a function" which is probably due to a collision. I see the '<script type="text/javascript" src="//www.google.com/jsapi?callback=load_ivory_google_map_api"></script>' is in there twice and a function "function load_ivory_google_map_api ()" is declared twice with different content.

I am using the following on the page:

{{ $autocompleteHelper->renderJavascripts($autocomplete) }}
{{ $mapHelper->renderJavascripts($map) }}

{{}} are Laravel's blade echo statements.

I am using this in a Laravel project via composer ("egeloen/google-map": "1.4.*@dev")

@egeloen
Copy link
Owner

egeloen commented Aug 30, 2014

Do you use both as async?

@sschueller
Copy link
Author

yes

        $autocomplete = new Autocomplete();

        $autocomplete->setPrefixJavascriptVariable('place_autocomplete_');
        $autocomplete->setInputId('search_location');
        $autocomplete->setInputAttribute('class', 'form-control input-lg');
        $autocomplete->setInputAttribute('placeholder', Lang::get('listings.location'));
        $autocomplete->setInputAttribute('name', 'search_location');
        $autocomplete->setTypes(array(AutocompleteType::CITIES));
        $autocomplete->setAsync(true);
        $autocomplete->setLanguage(App::getLocale());


        $map = new Map();
        $map->setPrefixJavascriptVariable('map_');
        $map->setHtmlContainerId('map_canvas');

        $map->setAsync(true);
        $map->setAutoZoom(false);

        $map->setCenter($latitude, $longitude, true);
        $map->setMapOption('zoom', 11);

        $map->setMapOption('mapTypeId', MapTypeId::ROADMAP);

        $map->setMapOption('disableDefaultUI', true);
        $map->setMapOption('disableDoubleClickZoom', true);
        $map->setMapOptions(array(
            'disableDefaultUI'       => true,
            'disableDoubleClickZoom' => true,
        ));

        $map->setStylesheetOptions(array(
            'width'  => '800px',
            'height' => '400px',
        ));

        $map->setLanguage(App::getLocale());

            $marker = new Marker();

            $marker->setPrefixJavascriptVariable('marker_');
            $marker->setPosition($listing->lat, $listing->lon, true);
            $marker->setAnimation(Animation::DROP);

            $marker->setIcon(asset('img/pin.png'));

            $marker->setOptions(array(
                'clickable' => true,
                'flat'      => true,
            ));

            // info window for marker
            $infoWindow = new InfoWindow();

            $infoWindow->setPrefixJavascriptVariable('info_window_');
            $infoWindow->setPosition(0, 0, true);
            $infoWindow->setPixelOffset(1.1, 2.1, 'px', 'pt');
            $infoWindow->setContent(View::make('listing.mappinpopup', array('listing' => $listing))->render());
            $infoWindow->setOpen(false);
            $infoWindow->setAutoOpen(true);
            $infoWindow->setOpenEvent(MouseEvent::CLICK);
            $infoWindow->setAutoClose(true);
            $infoWindow->setOptions(array(
                'disableAutoPan' => true,
                'zIndex'         => 10,
            ));

            $marker->setInfoWindow($infoWindow);

            $map->addMarker($marker);

@egeloen
Copy link
Owner

egeloen commented Aug 30, 2014

Unfortunately, this is a known limitation which will be fixed in the next major release... I have explained a workaround (pretty complicated) in egeloen/IvoryGoogleMapBundle#96

@egeloen egeloen added the bug label Aug 30, 2014
@soerenmartius
Copy link

Hey egeloen, do you have an timing for the next major release?

@egeloen
Copy link
Owner

egeloen commented Oct 7, 2014

@caramba1337 Basically, I have created egeloen/ivory-http-adapter in order to replace widop/http-adapter for the google map library in the middle of my refacto. This is mainly why it takes some more time to refactor. Anyway, It is well advanced but not fully finished (I have one part to refactor/finish and obviously, I have to rewrite the doc). It should not take me a long time to finish, so I hope in the next weeks, it will be available in a dedicated branch, then you can try it and give me some feedbacks :)

Btw, this issue is already fixed in my refacto (You will be able to use as many maps/autocompletes you want in a single page)

@soerenmartius
Copy link

@egeloen Thank you for the information.

@egeloen
Copy link
Owner

egeloen commented Aug 12, 2016

Your issue has been fixed by #134 but will only be part of the 2.x version.

@egeloen egeloen closed this as completed Aug 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants