4

I am trying to update the google map of PrimeFaces with the new latitude, longitude with the help of p:ajax, but it is not working...I'm using JSF 2.0. I have used p:ajax earlier in the similar way and it worked beautifully. Any idea why this does not work? The following is the code, contForm is the id of the form.

<h:outputText value="Latitude :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapLatitude}" size="10">
    <p:ajax event="blur" update="contForm:gMapID"/>
</h:inputText>
<h:outputText value=" Longitude :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapLongitude}" size="10" >
    <p:ajax event="blur" update="contForm:gMapID"/>
</h:inputText>
<h:outputText value=" Marker :"/>
<h:inputText value="#{confirmBrandRegistration.newBrand.mapMarker}" size="20" >
    <p:ajax event="blur" update="contForm:gMapID"
            listener="#{confirmBrandRegistration.updateMarker}"/>
</h:inputText>
</h:panelGrid>

<p:outputPanel id="gMapID">
    <f:view contentType="text/html">
        <p:gmap center="#{confirmBrandRegistration.newBrand.mapLatitude}, #{confirmBrandRegistration.newBrand.mapLongitude}" 
                zoom="16" type="HYBRID" streetView="true"
                model="#{confirmBrandRegistration.simpleModel}"
                style="width:500px;height:400px" />
    </f:view>
</p:outputPanel>
Daniel Szalay
  • 4,041
  • 12
  • 57
  • 103
user644745
  • 5,673
  • 9
  • 54
  • 80

1 Answers1

5

I solved it right now:)

index page:

<h:panelGroup id="pmap">
    <p:inputText value="#{mapManager.address}" label="Adresa" />
    <h:outputText value="#{mapManager.geo}" id="m" />
    <p:commandButton value="OK" actionListener="#{mapManager.updateMapCenter(ae)}" update="pmap" />
    <p:gmap  center="#{mapManager.geo}" 
             zoom="7" 
             type="HYBRID"    
             style="width:800px;height:400px" 
             streetView="true"
             model="#{mapManager.map}"
             overlaySelectListener="#{mapBean.onMarkerSelect}"
             >
        <p:gmapInfoWindow>  
            <p:outputPanel style="text-align:center; display:block; margin:auto:">
                <h:outputText value="#{mapManager.marker.title}" />  
                wserw
            </p:outputPanel>  
        </p:gmapInfoWindow>  
    </p:gmap>
</h:panelGroup>

part of managed bean:

private MapModel map;
private Marker marker;
private String address;
private String geo="49.817491999999992, 15.4729620";

public MapManager() {
}

@PostConstruct
public void init() {
    events = edao.findAll();
    map = new DefaultMapModel();
    for (Event event : events) {  
        Marker m=new Marker(new LatLng(event.getLat(), event.getLng()), event.getName());
        map.addOverlay(m);
    }
}

public void updateMapCenter(ActionEvent ae) {
    GMapService gs=new GMapService();
    LatLng geo=gs.getGeocode(address);
    this.geo=geo.getLat()+","+geo.getLng();
}

hope it solved your problem.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
user1000807
  • 51
  • 1
  • 2
  • Thanks. I remember solving the problem at that time when I was using it.. dont remember now the context... – user644745 Oct 19 '11 at 10:36
  • what is wrong with people in the world these days. this question/answer was viewed 3038 times (today, as I am writing this topic), and I am the first one adding a +1 vote to 'both' the question and answer? and why am I here? I'm trying to help others on PrimeFaces forum, so I provided URL of this stackoverflow question to a recently-asked question in PrimeFaces Core forum, and this showed up first in google search results. – Howard May 31 '13 at 06:51
  • what's your primeFaces version ? I've never seen the gmap.overlaySelectListener attribute again – yannicuLar Sep 27 '13 at 09:10
  • Is GMapService a class implemented by your own? – Juampa Feb 04 '14 at 03:21