تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
8566 أدوات العرض

Hi Odoo developers,

Am currently building a custom module in Odoo 13.Is it possible to find the location latitude and longitude from an address using python.

I have the details in the contact form such as street,state,country etc..

Thanks

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

BY default in odoo itself, there is such functionality, if you go to partners form view, you can see a page named Partner Assignation, make sure that the module named base_geolocalize is installed in the database.

Once the module is installed you can see the latitude and longitude is coming based on the address of the partner on clicking the Geo Locate Button,


See the code of the corresponding button action:


@classmethod
def _geo_localize(cls, apikey, street='', zip='', city='', state='', country=''):
search = geo_query_address(street=street, zip=zip, city=city, state=state, country=country)
result = geo_find(search, apikey)
if result is None:
search = geo_query_address(city=city, state=state, country=country)
result = geo_find(search, apikey)
return result

@api.multi
def geo_localize(self):
# We need country names in English below
apikey = self.env['ir.config_parameter'].sudo().get_param('google.api_key_geocode')
for partner in self.with_context(lang='en_US'):
result = partner._geo_localize(apikey,
partner.street,
partner.zip,
partner.city,
partner.state_id.name,
partner.country_id.name)
if result:
partner.write({
'partner_latitude': result[0],
'partner_longitude': result[1],
'date_localization': fields.Date.context_today(partner)
})
return True


File in Github:  https://github.com/odoo/odoo/blob/13.0/addons/base_geolocalize/models/res_partner.py


Thanks

الصورة الرمزية
إهمال
الكاتب

thanks niyas

if form how to capture the latitude & longitude value from action button in odoo

المنشورات ذات الصلة الردود أدوات العرض النشاط
4
مايو 24
11807
1
أبريل 24
2580
0
نوفمبر 23
1483
1
سبتمبر 23
1586
2
أغسطس 23
3827