Advertisement:

Author Topic: Google Maps improve improve improve :-)  (Read 7107 times)

kingsult

  • Premium
  • Full Member
  • *****
  • Posts: 204
Google Maps improve improve improve :-)
« on: June 16, 2011, 10:52:51 pm »
Hi,

I am working on improving the precision of the Google Maps. I see that the geocoding is not working fine.

I am trying to include a map in the post-item form. This way users can drag the marker to the exact location.
I would need some help on posting the latitude and longitude into the DB and thus bypassing the encoding.

Can anyone help me for the posting part ? I will work on the functionality of the map.

Thanks,


kingsult

  • Premium
  • Full Member
  • *****
  • Posts: 204
Re: Google Maps improve improve improve :-)
« Reply #1 on: June 16, 2011, 11:42:41 pm »
Hi,

Here is a copy of the code I have been working on. I still have a problem when I release the marker. It does not jump.

I also still need to know how to submit the latitude and longitude into the DB.

Thanks for the support...

Code: [Select]
<!-- Google maps (create + edit markers) -->
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAYWVprCLmLlLyu9Pr6u9XZBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQX87GFVbk-BkgxiiREH_unTJNQfg" type="text/javascript"></script>

        <!-- Google maps (create + edit markers) -->
<script type="text/javascript">
    //<![CDATA[
    // global variables
var marker;
var map;

function centerMarker() {
marker.setPoint(new GLatLng(map.getCenter().lat(), map.getCenter().lng()))
  document.getElementById('edit-field-latitude-0-value').value = marker.getPoint().lat();
  document.getElementById('edit-field-longitude-0-value').value = marker.getPoint().lng();
}



function createMap(){
if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl3D());
     
     
      var center = new GLatLng(18.058477018417005,-63.0856418609619);map.setCenter(center, 13);     
//map.setMapType(G_SATELLITE_MAP);
map.setMapType(G_HYBRID_MAP);

//Min-max values of the zoom
G_HYBRID_MAP.getMinimumResolution = function () { return 10 };
G_HYBRID_MAP.getMaximumResolution = function () { return 18 };


marker = new GMarker(center, {draggable: true});
GEvent.addListener( marker, "dragstart", function() {map.closeInfoWindow();});
GEvent.addListener(marker, "dragend", function() {
document.getElementById('edit-field-latitude-0-value').value = marker.getPoint().lat();
document.getElementById('edit-field-longitude-0-value').value = marker.getPoint().lng();
});
map.addOverlay(marker);
}else{
      alert("Sorry, the Google Maps API is not compatible with this browser");
}
}
//]]>
    </script>


Also add
Code: [Select]
<body onLoad="createMap()" >

Call the map using:
Code: [Select]
<div id="map" class="gmapedit"></div>
And modify the css file by adding:
Code: [Select]
.gmapedit
{
    width: 100%;
    height: 450px;
    float: left;
    margin-bottom: 5px;
    margin-top: 5px;
    #margin-top: 15px;
}

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Google Maps improve improve improve :-)
« Reply #2 on: June 17, 2011, 10:32:36 am »
Hi kingsult,

How are you doing this? editing the theme directly? with a plugin?

We have several "hooks", so the best an easy way should be create a plugin.

Use the hook "item_form" to load your map at posting page ("item_edit" for editing), there, you put the map, and TWO "hidden inputs" (don't worry, those two inputs and the map should appear inside the <form> tags, so the variables should be sent when the form is submitted. With some JS magic, you should change the content of those hidden inputs with the data of your maps.

Later use "item_form_post" (and "item_edit_post") to handle the variables (Params::getParam("name_of_the_var")) and save them on the database.


You could use any of the attributes plugin as a base, and ask here anything.

Thanks!!

kingsult

  • Premium
  • Full Member
  • *****
  • Posts: 204
Re: Google Maps improve improve improve :-)
« Reply #3 on: June 17, 2011, 04:59:12 pm »
Hi Conejo,

I was editing the file directly. The plugin option is a great idea. I still need to play around to be able to make the calls.

Can we integrate it into the Google Maps plugin ? If yes, can you give me some guidance ?

I have finished the code that needs to be inserted in the item post page.

Thanks,

keny

  • Full Member
  • ***
  • Posts: 137
Re: Google Maps improve improve improve :-)
« Reply #4 on: June 27, 2011, 10:55:52 pm »
I think we just need a postal code /zip code and set the map according of the zip. Google map in my case show the wright location with only my postal code.

But maybe ist not the case in some country ?

The best way should wait for html5 to be standard and retreive geolocation directly from browser but again IE like always still not support this option.

Anyway tell me if you only put your zip/postal code in the adress field do you get the wright location ?

kingsult

  • Premium
  • Full Member
  • *****
  • Posts: 204
Re: Google Maps improve improve improve :-)
« Reply #5 on: June 28, 2011, 08:06:39 pm »
My site is based on an island that is not using zip codes. There are many places in the world where zip codes are not being used (for example: Ireland). I can send you my code. It shows a google map and allows you to pinpoint the exact location.


keny

  • Full Member
  • ***
  • Posts: 137
Re: Google Maps improve improve improve :-)
« Reply #6 on: June 28, 2011, 08:55:28 pm »
If you do not use zip code how mail system work in ireland ? I am just curious to know. Did all people have a unique street address number ?

Send me your code in pm i will check that when i finish my current pluggin and i will try to make you something but again wihout warranty of succes !

If you have a live demo working ist will be appreciate so i can see exactly what you want.


keny

  • Full Member
  • ***
  • Posts: 137
Re: Google Maps improve improve improve :-)
« Reply #7 on: June 29, 2011, 06:14:19 am »
I have start working on it and i think that it should work

The good thing is that i will only update current pluggin and not create a new one.

You should test beta tomorow if everything work.


Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: Google Maps improve improve improve :-)
« Reply #8 on: June 29, 2011, 02:10:21 pm »
I have start working on it and i think that it should work

The good thing is that i will only update current pluggin and not create a new one.

You should test beta tomorow if everything work.

As I said in another post, it will be great if you can pull request to the plugins repository https://github.com/osclass/osclass-plugins/tree/google_maps

keny

  • Full Member
  • ***
  • Posts: 137
Re: Google Maps improve improve improve :-)
« Reply #9 on: June 29, 2011, 04:51:13 pm »
Yes i will try and if need help will contact you

keny

  • Full Member
  • ***
  • Posts: 137
Re: Google Maps improve improve improve :-)
« Reply #10 on: June 30, 2011, 04:10:32 pm »